Reputation: 97
I have a simple radio group. Now what I'm trying to work out, no success yet, is how to alert()
the values of the radio buttons that were not checked.
HTML:
<div id="radiogrouping">
<input type="radio" name='test' value="hello"> hello <br/>
<input type="radio" name='test' value="hello again"> hello again <br/>
<input type="radio" name='test' value="yet again hello"> yet again hello <br/>
</div>
JS:
$(function(){
$("#radiogrouping").bind("change",function(value){
var test = $(this).children(":not(:checked)").val();
alert(test);
});
});
The JS above will alert()
the value of the first radio button if it is not checked, but only the first.
How do I get both radio button values that are not checked to be alerted?
Thanks in advance for any help.
Upvotes: 0
Views: 80
Reputation: 388326
Use .map() to get an array of unchecked values
$("#radiogrouping").bind("change", function (value) {
var test = $(this).children(":not(:checked)").map(function () {
return this.value
}).get();
alert(test);
});
Demo: Fiddle
When you use .val() it gets the values of the first checkbox that is not checked
Upvotes: 3