Reputation: 298
here's my html mark up
<span class="wpcf7-form-control-wrap radio-20">
<span class="wpcf7-radio radio-20" id="radio-20">
<span class="wpcf7-list-item">
<span class="wpcf7-list-item-label">Yes</span>
<input type="radio" value="Yes" name="radio-20">
</span>
<span class="wpcf7-list-item">
<span class="wpcf7-list-item-label">No</span>
<input type="radio" value="No" name="radio-20">
</span>
</span>
</span>
how would i know of the "Yes" radio button or the "No" is checked?
i tried:
jQuery("span#radio-20 span input").val("Yes").click(function (){
alert('bang!');
});
but it will alert also when i click "No";
can somebody Help me?
Upvotes: 1
Views: 1106
Reputation: 3461
You can do this:
var val = $("#radio-20").find(":checked").val();
if (val === "Yes") {
// "Yes" button checked
} else {
// "No" button checked
}
If you want a function to be called when a button is checked, you can do this:
$("#radio-20 input").click(function () {
var val = $(this).val();
if (val === "Yes") {
// "Yes" button checked
} else {
// "No" button checked
}
});
(I have not tested these but it should work)
Upvotes: 4
Reputation: 338148
jQuery("span#radio-20 span input[value=Yes]").click(function (){
alert('bang!');
});
Upvotes: 3
Reputation: 50966
jQuery("span#radio-20 span input").click(function (){
if ($(this).val() == "Yes"){
alert('bang!');
}
});
Upvotes: 3