Skip to content Skip to sidebar Skip to footer

How Do I Change The Input Name In Jquery

This is what I am currently trying to achieve: I am trying to clone a form and change the input name. How would I pull this off. JS: $(document).ready(function() { var counter =

Solution 1:

To change an input name just use attr() method

$('input').attr('name', 'yourNewname');

and I remarque that you have input without Id so you should use one of those methods:

1/ give each input an Id for example #input1#input2

$('#input1').attr('name', 'yourNewname1'); // change the name of first input

$('#input2').attr('name', 'yourNewname2'); // change the name of first input

or

you can use eq()

$('input').eq(0).attr('name', 'yourNewname1'); // change the name of first input

$('input').eq(1).attr('name', 'yourNewname2'); // change the name of first input

Solution 2:

To change any attribute including name you can do this

$('#myInputFieldId').attr('name','new_name')

Hope it helps

Solution 3:

Try this: $('input[name="0angle"]').attr('name', 'new-name');

Post a Comment for "How Do I Change The Input Name In Jquery"