Search code examples
htmljqueryradio-button

Radio button jQuery change doesn't work


sorry if this is a repost, I've looked around and cannot find a solution that works.

I have to radio buttons, and I want to execute a function when they are changed. From other posts I thought this should work

$(function() {
    $("#isMale").change( function() {
        alert("test");
        location.href = 'http://google.com'
    }
});

http://jsfiddle.net/BfMYF/1/

But it doesn't, can anyone help ?


Solution

  • The selector is wrong, but you need to close .change function brackets properly too:

    $(function() {
        $("input[name=isMale]").change( function() {
            alert("test");
            location.href = 'http://google.com';
        });
    });