puppy
puppy

Reputation: 57

how to change the field name of the input box when cloning dynamically in jquery

how to change the field name of the input box when cloning dynamically in jquery.

I am having like this

<script>
var i=0;
var input_name=null;
$('#box').each(function(){ 
  $('#sub').click(function(){ 
    var cln= $('#box').clone()
       .attr('name', input_name + '[' + i + ']');
    i++;
   });
});     
</script>

Thanks!!!!

Upvotes: 1

Views: 262

Answers (1)

Baby
Baby

Reputation: 26

Yes Puppy, You have to replace'id' with class. Because you cant use same id value for more than one input field.

<script>
var i=0;
var input_name=null;
$('.box').each(function(){ 
   $('.sub').click(function(){ 
     var cln= $('#box').clone()
     .attr('name', input_name + '[' + i + ']');
     i++;
   });
alert('i love you puppyma');
}); 
</script>

Upvotes: 1

Related Questions