Mac Taylor
Mac Taylor

Reputation: 5148

problem to get radio input box value in jquery

guys i need to get the value of a input radio box so i wrote this code

if ($("input[@name='notify']:checked").val() == '1'){
    var notifyme=1;
} else {
    var notifyme=0;
}

but everytime i send the request through php function it says notifyme var is 1 and even i checked 0 radio box it still says the value is 1

html part

<input type="radio" name ='notify' value="1" >YES 
<input type="radio" name ='notify' value="0" >NO 

Upvotes: 1

Views: 446

Answers (3)

redsquare
redsquare

Reputation: 78667

Lose the @ prefix on the attribute. The xslt based syntax has been removed since 1.4+

if ( $("input[name='notify']:checked").val() ){
    var notifyme=1;
} else {
    var notifyme=0;
}

Upvotes: 5

Anurag
Anurag

Reputation: 141879

Why not just,

var notifyme = $('input[name=notify]:checked').val()

Upvotes: 1

gnome
gnome

Reputation: 1133

looks correct to me, http://www.jsfiddle.net/sjRcZ/1/ You sure that jquery is loading?

Upvotes: 0

Related Questions