Reputation: 7688
So, I have 3 radio buttons:
<input type="radio" name="status" value="enabled" class="radio" <?php if($news_row['status']==1) echo 'checked'; ?> />
<input type="radio" name="status" value="disabled" class="radio" <?php if($news_row['status']==2) echo 'checked'; ?> />
<input type="radio" name="status" value="timer" class="radio" <?php if($news_row['status']==3) echo 'checked'; ?> />
And I'm trying to check if radio button with value timer is checked like so
if($('.radio [value=timer]').is(':checked')) {
console.log('timer');
}
But obviously I'm doing something wrong since that code above doesn't work. So, which is the right way to do it? Using .change()
?
Upvotes: 2
Views: 7490
Reputation: 34107
Demo http://jsfiddle.net/m4m57/5/
Issue was the space
here f ($('.radio [value=timer]').is(':checked')) {
^-----------
Hope this helps,
code
$('input').on('change', function() {
if ($('.radio[value=timer]').is(':checked')) {
alert('say what');
console.log('timer');
}
});
Upvotes: 4
Reputation: 9080
Remove space:
if($('.radio[value=timer]').is(':checked')) {
console.log('timer');
}
You had space in .radio [value=timer]
which means a different selector eg it meant select all elements with value attribute set inside an element with class radio at any nested level
Removing the space means select all elements with class radio AND value attribute set
Upvotes: 1