- Newbie here with jquery
- I would like to add a couple of input fields to a form I have already created
- Reason is - in case a new user wants to add new degree to the one already in the database
This is my jquery code
$("#addinst").click(function(){ $("mainform").append("<p> <label align="left">Institution #1:</label> <input name="EdInstitutionName1" type="text" value="" size="70" maxlength="100" /> </p>");This is part of the form the form
<form id="someform" > <fieldset id="mainField"> <p><label align="left">Institution #1:</label> input name="EdInstitutionName1" type="text" value="" size="70" maxlength="100" /> tr> td align="left">City, State #1:</td> td><input name="EdInstitutionLocation1" type="text" value="" size="70" maxlength="100" /></td> </tr>
Add a comment
|
1 Answer
It seems that inside of your jQuery code, you are missing the id of the form. To select your form, use:
$('#mainform').append
instead of
$('mainform').append
In jQuery, ids need to have a # in front of them. Without a # symbol, jQuery looks for tags with that name. Similarly, classes are selected using . in front of the class name.
For more information about jQuery selectors, you can refer to the jQuery selector API
2 Comments
koba
Thanks Kyle, here is my fiddle link for clarity. jsfiddle.net/koba/58tmm/2 The idea is to create 5 new input fields to add another institution, I have it trying to insert a field first for test, but nothing appears to be working
Kyle
@koba In your fiddle, you don't have anything with an id of
mainform. I updated your fiddle: jsfiddle.net/58tmm/6