We have dynamic ID’s generated from a database like this:
<input type="radio" id="brand1" value="1">
<input type="radio" id="brand1" value="2">
----
<input type="radio" id="brand2" value="1">
<input type="radio" id="brand2" value="2">
How can I get/alert, through a click on a radio button, which ID it is?
(I guess my error is in the first line: ‘input#brand’.)
$('input#brand').live('click',function() {
var radiovalue = $('input[name=brand + id]:checked').val()
alert(radiobuttonID + radiovalue);
});
You would use something like this to get id:
and this to get value:
Notice that we can put a live click handler on all of the elements that start with (
^=) “brand”.See JSFiddle