user1443519
user1443519

Reputation: 589

Detecting change in dynamically generated radio buttons with jQuery

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.

Upvotes: 2

Views: 848

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67197

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

$('input[name^="data[Setting]"]').change(function(){  });

Upvotes: 2

Related Questions