I want to use javascript to create <input/> tags with a dynamic id (name attribute will be the same) depending on the order in which they appear.
I have the first <input/> tag in plain html and a div that should append a new <input/> with an incremented id when clicked:
<input type="text" name="1" id="1" />
<div class="add_new" onClick="add_new_input()">+</div>
Now, the javascript needs to count the amount of <input/>s currently being displayed (count) and use that amount to generate a dynamic id (count+1).
Therefore if the <div class="add_new"><.. is clicked twice, the output should be as follows:
<input type="text" name="1" id="1" />
<input type="text" name="2" id="2" />
<input type="text" name="3" id="3" />
If I append the new <input/> tag in my form using jquery's append(), would this add to the previously appended <input/>s? Or would I need to append one <input/>, then two, then three, etc?
Also, how can I use javascript to count the amount of <input/>s currently being displayed?
$(':input:text').size()to count the text input control