views:

547

answers:

3

I have the following radio buttons, none of which is checked by default.

<input type="radio" name="location" value="0" /> home
<input type="radio" name="location" value="1" /> work
<input type="radio" name="location" value="2" /> school

How do I detect when either of them is checked. I'm looking for something like click, but it's not working

$("input[name=location]").click(function(){
    alert("selected");
});
+2  A: 
$('input[name=location]').change(function(){
    alert(this.checked);
});
Darin Dimitrov
+1  A: 

Have you treid the onChange event?

$("input[name=location]").bind('change', function(){
    alert("selected");
});
T. Stone
+1  A: 

This works fine for me. Are you referencing well the jquery library?

eKek0
It looks like it was a bug with something above this line, and it messed up the whole javascript below it.
Chris