Thursday 31 January 2013

How to make a group of checkbox behave like a Radio button or toggle button using JQuery

 I got a message from my project manager that the client wants check-box like look rather than radio buttons for Roles(such as Admin, Site Manager) but it need to behave like the radio button. so to do it I had applied below the Jquery snippet to achieve it.

 $('input[name="Roles"]:checkbox').click(function () {
            var group = "input:checkbox[name='" + $(this).attr("name") + "']";
            $(group).attr("checked", false);
            $(this).attr("checked", true);
        });


Note:Here I am showing two check-boxes but you can keep n-numbers of and select only one like the radio button group.

No comments:

Post a Comment