tags:

views:

36

answers:

3

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 
+5  A: 

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;
}
redsquare
["deprecated"](http://en.wikipedia.org/wiki/Deprecation) implies that the feature still exists and hasn't been removed yet, but should be avoided because it may be removed in the future. It's only deprecated, so having the @ there shouldn't make a difference.
Andy E
smart answer , thanks
Mac Taylor
A: 

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

gnome
It's not, check this out: http://jsfiddle.net/XgGWH/. Works fine. Now add the `@` and watch it explode.
karim79
@karim79: yet this works (with `@`): http://www.jsfiddle.net/sjRcZ/2/
Andy E
@Andy E, interesting stuff :)
karim79
Interesting. `@` works when `:checked` filter is present. Without it, the expression becomes invalid. Better to let go off `@`.
Anurag
@Anurag: yeah, there's definitely something weird going on there. I couldn't find any docs on whether `@name` for attributes was removed or just deprecated. Oh well, I guess it doesn't matter that much - just don't do it like you said :-)
Andy E
+1  A: 

Why not just,

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