I have two complex UX jQuery issues I'm working on right now. I am cloning 2 forms of variables using jQuery. How can I index them, so I can mark them with this identifier. For example, if I select 3 from the selection window, I should get 3 lines of the form, and on the left side of each line should start with a number starting with 1. form, 2. form, 3 form.
The second problem I want is to confirm the companion function [] against confirmattendant []. How do I do this inside the cloned HTML.
Here is my JSFiddle
http://jsfiddle.net/tGprH/5/
Here is my HTML code:
<select name="select" id="select">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<br/>
<p>Email address, Confirm Email Address</p>
#1 <input type="text" name="attendant[]"/>
<input type="text" name="confirmattendant[]"/>
<br/>
<div id="container">
</div>
Here is my jquery
$("select").change(function() {
var select = parseInt($('#select').val() , 10);
var $clone = '<input type="text" name="attendant[]" /><input type="text" name="confirmattendant[]" /><br/>';
console.log($clone);
var html = '';
for(var i = 1;i< select ; i++){
html += $clone;
}
$('#container').empty().html(html);
}).change();
source