2

I'm trying to detect changes in dynamically generated radio buttons. I have a form that generates radio buttons and they're named according to their ID saved in the database. So it's something like

<input type="radio" name="data[Setting][47]" id="Setting47Entry" value="entry">
<input type="radio" name="data[Setting][47]" id="Setting47Standard" value="standard">

<input type="radio" name="data[Setting][48]" id="Setting48Entry" value="entry">
<input type="radio" name="data[Setting][48]" id="Setting48Standard" value="standard">

<input type="radio" name="data[Setting][49]" id="Setting49Entry" value="entry">
<input type="radio" name="data[Setting][49]" id="Setting49Standard" value="standard">

There is not pre-defined number of radio buttons that will appear. There could be 2 or even 20, it all depends on other options that the user has set.

I know how to detect changes if the names were static, but since the names are different for each user I don't know how to handle that.

1
  • 2
    if names are dynamic then use something static like classname Commented Dec 29, 2013 at 17:27

1 Answer 1

2

Why don't you use a attribute starts with selector try,

$('input[name^="data[Setting]"]').change(function(){  });
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, it's detecting changes. I'm able to retrieve the newly selected value with $(this).val(), but how can I retrieve the name or id? I need to know not only the value, but the input itself.
you can access name/id etc.. using $(this) inside of that handler. can you tell me exactly what do you need.? may be an example.
Nevermind, I figured it out. I used $(this).attr('name')
@user1443519 you can simply use $(this).attr('name') to know that.!

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.