Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable radio group by checkbox?

I did search all over but i still cant fix it. Please help:

Here is my js code:

<script type="text/javascript">
    $(document).ready(function() {
        $("#email_acc").click(function() {
            if ( $(this).is(":checked") ) {
                $("#email_group").attr("enabled","enabled");
            }
        });  

        $("#system_acc").click(function() {
            if ( $(this).is(":checked") ) {
                $("#system_group").attr("enabled","enabled");
            }
        }); 
    });
</script>

The following shows my html code:

<input type="checkbox" name="email_acc" id="email_acc" />Email Account
<input type="checkbox" name="sys_acc" id="sys_acc" />System Account

<input type="radio" name="radio_email" value="create" class="email_group" id="radio_email_0" disabled="disabled"/>New
<input type="radio" name="radio_email" value="change" id="radio_email_1" disabled="disabled"/>Change
<input type="radio" name="radio_email" value="terminate" id="radio_email_2" disabled="disabled"\ />Termination

<input type="radio" name="radio_system" value="create" class="system_group" id="radio_system_0" disabled="disabled"/>New
<input type="radio" name="radio_system" value="change" id="radio_system_1" disabled="disabled" />Change
<input type="radio" name="radio_system" value="terminate" id="radio_system_2" disabled="disabled" />Termination

I donno what is the problem.It just doesn't work.

like image 708
Newbie Avatar asked Oct 05 '22 21:10

Newbie


1 Answers

$(document).ready(function() 
{

    $("#email_acc").click(function()
    { 
        if ( $(this).is(":checked") ) 
        {  
            $("input[name='radio_email']").removeAttr("disabled");
           //      ^----------------enable all the checkbox with common name
        }
    });  

    $("#sys_acc").click(function()
   //     ^---------corrected id
    {
        if ( $(this).is(":checked") )
        {   $("input[name='radio_system']").removeAttr("disabled");
       //         ^----------------enable all the checkbox with common name
        }
    }); 
});​

DEMO

DEMO 2

Code updated for new requirements from OP, cleaned code thanks to nnnnnn

UPDATED DEMO 3

like image 184
Sibu Avatar answered Oct 10 '22 04:10

Sibu