Reputation: 305
I have dynamically created radio buttons and have assigned them ids. Now when i try,
function updateAO(id2) {
var status = $('input[name=id2]:checked').val();
alert(status);
}
It prints undefined. Can anyone please tell how to get this value. Thanks in advance!!
Upvotes: 0
Views: 94
Reputation: 2330
To get the selected radio button value use
function updateAO(id2) {
var status = $('input[name=id2]:checked').val();
alert(status);
}
To select normal radio button use
function updateAO(id2) {
var status = $('input[name=id2]').val();
alert(status);
}
Upvotes: 0
Reputation: 71150
The :checked
selector will only select inputs currently checked, if the passed input isnt checked at the time, status will remain unset, try changing your JS to:
function updateAO(id2) {
var status = $('input[name='+id2+']').val();
alert(status);
}
Upvotes: 1
Reputation: 25310
You're not using your parameter correctly.
var status = $('input[name="' + id2 + '"]:checked').val();
Upvotes: 1