Wednesday, June 15, 2016

Handle radio group change event #javascript #jquery

If you need to handle the event where the user selects a different radio group option, then here's the code to do that.

Code
radioGroupChangeHandler= function(e){
    switch(e.target.id)
    {
        case "radioGroupOption1":
            console.log("option 1 was selected")
            break;
        case "radioGroupOption2:            console.log("option 2 was selected")
            break;
    }
}

$("input[name='radioGroupName']").change(radioGroupChangeHandler)

No comments:

Post a Comment

There was an error in this gadget