0

I have a group of RadioButton which will set off an onclick event. The pageLoad and onclick event (SecurityCheckedChanged) work because the other show/hide JavaScript code works. I've commented it out to give a minimal example. However, setting disable true/false in SecurityCheckedChanged doesn't seem to work (it does work in pageLoad though). Is what I'm doing correct or is there another way to enable/disable a TextBox?

JavaScript:

function pageLoad(sender, args) {
    $("#<%= textBoxPassword.ClientID %>").attr("disabled", true);
    //more show/hide code
}

function SecurityCheckedChanged() {
    if ($("#<%= radWEP.ClientID %>").is(':checked')) {
        $("#<%= textBoxPassword.ClientID %>").attr("disabled", false);
        //more show/hide code
    }
    else if ($("#<%= radWPA.ClientID %>").is(':checked') || $("#<%= radWPA2.ClientID %>").is(':checked')) {
        $("#<%= textBoxPassword.ClientID %>").attr("disabled", false);
        //more show/hide code
    }
    else {
        $("#<%= textBoxPassword.ClientID %>").attr("disabled", true);
        //more show/hide code
    }
}

HTML:

<div style="text-align: left;">
    <asp:Localize ID="locPassword" runat="server" Text="Password:" meta:resourcekey="locPasswordRc1" />
    <asp:TextBox ID="textBoxPassword" TextMode="Password" runat="server"></asp:TextBox>
</div>


<div style="text-align: left;">
    <asp:RadioButton id="radNone" Text="None" Checked="True" meta:resourcekey="radNoneRc1"
        GroupName="RadioGroupSecurity" runat="server" onclick="SecurityCheckedChanged()"/>

    <asp:RadioButton id="radWEP" Text="WEP" Checked="False" meta:resourcekey="radWepRc1"
        GroupName="RadioGroupSecurity" runat="server" onclick="SecurityCheckedChanged()"/>

    <asp:RadioButton id="radWPA" Text="WPA" Checked="False" meta:resourcekey="radWpaRc1"
        GroupName="RadioGroupSecurity" runat="server" onclick="SecurityCheckedChanged()"/>

    <asp:RadioButton id="radWPA2" Text="WPA2" Checked="False" meta:resourcekey="radWpa2Rc1"
        GroupName="RadioGroupSecurity" runat="server" onclick="SecurityCheckedChanged()"/>
</div>

NOTE: Also, I understand I shouldn't intermix C# code here. I'll get to cleaning that up a bit later.

  • 4
    Don't use `.attr("disabled", true/false)` for setting the disabled state. Use `.prop("disabled", true/false)`. Technically, you'd want to **remove** the attribute to enable it, but just stick to using `.prop()` - http://api.jquery.com/prop/ - it's the suggested method for setting states like this. Here's some more info: http://stackoverflow.com/questions/5874652/prop-vs-attr – Ian Aug 22 '14 at 18:53
  • @Ian It still doesn't work with `prop(...)`. I forgot to mention that in the OP. I just tried it again, but no dice. – But I'm Not A Wrapper Class Aug 22 '14 at 19:00
  • Well then debug and make sure the right code is executing. And make sure the right elements are being selected – Ian Aug 22 '14 at 19:01

0 Answers0