0

How to change the name of input checkbox with jQuery?

I tried :

$('input[name="INPUT_NAME"]').prop('name', 'INPUT_NAME['+ id +']');

$('input[name="INPUT_NAME"]').attr('name', 'INPUT_NAME['+ id +']');

Note : i absolutely need to get INPUT_NAME with [ID] to tag it and make difference between multiple same input checkbox inside the same form.

Thanks for your help!

9
  • 1
    could you show relevant html code too? Commented Jun 28, 2013 at 12:37
  • 3
    What is wrong? For me $('input[name="INPUT_NAME"]').attr('name', 'INPUT_NAME[1]'); works Commented Jun 28, 2013 at 12:40
  • Is there any browser relevant issue? Commented Jun 28, 2013 at 12:40
  • 1
    I don't understand what isn't working Commented Jun 28, 2013 at 12:40
  • 1
    Maybe the OP is missing to wait until the dom is ready? Commented Jun 28, 2013 at 12:45

1 Answer 1

2

If you want to name your inputs using their id, then you can do

$('input[name="INPUT_NAME"]').attr('name', function(){
     return 'INPUT_NAME['+ this.id +']'
});

But really, there is no good reason I can imagine to do such a thing.

Sign up to request clarification or add additional context in comments.

1 Comment

seems fair enough, i'd say

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.