Question

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 ?

Was it helpful?

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';
    });
});

OTHER TIPS

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

You also had a missing semi and paran!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top