user3002885
user3002885

Reputation: 49

Checkboxs in JS

I have a little problem with JS function that I created in the Pic that I attached there is 2 CheckBoxes: CbMale,CbFemale and a button for ChangeSelection.. I want that when the CbMale is checked the CbFemale will be disabled and after the user click on the ChangeSelection button there is a message that asking if he want to change selection if he does click ok the two checkbox are enabled and unchecked...and going vice versa if he click on the cbFemale first.

![A picture of two check boxes labelled ‘male’ and ‘female’ with a button labelled ‘change gender’ after them.][1]

My JS:

  function ChangeSelection(sender, args) {
        radconfirm('Would you like to change gender?</br>', confirmDisableCallBackFn, 370, 200, null, 'Alert');
    }

     function confirmDisableCallBackFn(arg) {
         if (arg == true) {
             var cbMale = $find("<%=cbMale.ClientID %>");
             var cbFemale = $find("<%=cbFemale.ClientID %>");
             //check.set_checked(false);
             cbFemale.set_enabled(true);
             cbMale.get_checked(false);

         }
         else {
             check.set_checked(true); 
         }
     }

    function ChangeGender(sender, args) {
        var cbMale = $find("<%=cbMale.ClientID %>");
        var cbFemale = $find("<%=cbFemale.ClientID %>");
        if (cbMale.get_checked(true)) {
            cbFemale.set_enabled(false);
        } else {
            cbMale.set_enabled(false);
        }
     }

My asp Code:
 <telerik:RadButton ID="cbMale" runat="server" ToggleType="CheckBox" ButtonType="ToggleButton" AutoPostBack="False" Text="Male" OnClientClicked="ChangeGender" ></telerik:RadButton>
                               <telerik:RadButton ID="cbFemale" runat="server" ToggleType="CheckBox" ButtonType="ToggleButton" AutoPostBack="False" Text="Female"></telerik:RadButton>
                                <telerik:RadButton ID="btnEditPersonDescription" runat="server" Text="Change Gender" Width="120px" AutoPostBack="false" OnClientClicked="ChangeSelection">
                                <Icon PrimaryIconCssClass="rbEdit" PrimaryIconLeft="4" PrimaryIconTop="4"></Icon></telerik:RadButton>

https://i.sstatic.net/OBpgK.png

Upvotes: 0

Views: 94

Answers (1)

Ashrith
Ashrith

Reputation: 725

You are trying to simulate the behavior of radio buttons with check boxes. Its easier with radio buttons. If you select cbMale it will not allow you to select cbFemale and vice versa. So create a group of radio buttons.

---Edit--- http://www.w3schools.com/aspnet/showaspx.asp?filename=demo_radiobutton Please take a look at the demo. It will guide you.

Upvotes: 2

Related Questions