Why does the JQUERY clone function and add an identifier to it and validate the email value?

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();
+5
source
2

for, ..

html += '#'+(i + 1)+ ' '+$clone;

$("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 += '#'+(i + 1)+ ' '+$clone;
   }
   $('#container').empty().html(html);
})

0

: http://jsfiddle.net/tGprH/7/

$("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++){
        if(i >= 1)
            html +=  '#' + (i+1) + ' ' + $clone;
        else
            html += $clone;
    }
    $('#container').empty().html(html);
 }).change();

: http://jsfiddle.net/tGprH/8/

<button id="compare">compare</button>

$('#compare').click(function(){
   var $attendantArray =  $('input[name="attendant[]"]');
   var $confirmattendantArray =  $('input[name="confirmattendant[]"]');
   for(var i = 0;i< $attendantArray.length ; i++)
   {
       alert((i+1) + ' attendant [' + $($attendantArray[i]).val() + ' / ' + $($confirmattendantArray[i]).val() + ']')
   }
});
0

All Articles