htmlasp.netasp.net-controls

how to check a checkbox on the check of one checkbox in asp.net?


i have two checkboxes.

<asp:CheckBox ID="chkPODPrice" Text="Enable POD" runat="server" OnClick="JavaScript:EnableDisable(this);"/>

<asp:CheckBox ID="chckPurchaseEnabel" Text="Enable Buy" runat="server" ClientIDMode="Static" />

if 1st text box is checked , i need to check the other one too and i am doing this on click function but its not working. Help me out.

javascript function is

function EnableDisable(obj) {

    if (obj.checked) {

        $("#chckPurchaseEnabel").checked = true;
    } else {

    }
}

Solution

  • You want to set the attribute as below.

    $("#chckPurchaseEnabel").attr('checked', true);
    

    Example Fiddle: https://jsfiddle.net/x1aw734b/