Skip to content Skip to sidebar Skip to footer

Do Something On Selecting A Radio Button

I want to perform something with the help of jquery when a radio button is selected. Suppose the page has n number of radio button groups

Solution 1:

$(function(){
    $("input[name*='group1']").click(function(){
        alert("Clicked");
    });

});

Try this and don't forget to call the jquery file in the head section.

Solution 2:

Building on nyfer's answer, you could chain the ajax-calls in the success-callback of $.ajax:

$("input[name*='group1']").click(function(){
    $.ajax({

    success: function(){
        $.ajax({
            success:function(){
                $.ajax({});
            }
        });
    }
    });
});

It's sort of messy code, so I'd probably put the success-callbacks in named functions as opposed to anonymous functions as displayed above. Now, if you want one ajax call per button clicked as hinted in the question, I would implement a queue to enqueue and dequeue ajax calls. Enqueue items in the click event, and revisit the queue in the success-callback of every ajax-call to see if there are items left to process.

Post a Comment for "Do Something On Selecting A Radio Button"