Tim
Tim

Reputation: 952

asp.net controls with javascript

I know this is probably a simple fix but I can't seem to figure out the issue here...

I am trying to disable withinthepast text box when RadioButton1 is clicked.

<asp:RadioButton ID="RadioButton1" runat="server" Checked="True" GroupName="DateTimeQuery" OnClick="javascript:TimeRangeClickEvent()"/>
<asp:TextBox ID="withinthepast" runat="server" Text="1"></asp:TextBox>

<script>
        function TimeRangeClickEvent()
        {
            var radio1 = document.getElementById('<%=RadioButton1.ClientID%>').checked;                

            if (radio1 == true)
            {
                var within = document.getElementById('<%=withinthepast.ClientID%>').enabled = false;
            }
        }
    </script>

Any advice?

Upvotes: 0

Views: 57

Answers (2)

Martin Parenteau
Martin Parenteau

Reputation: 73721

The problem is probably with the "enabled" property. You can try this:

To enable a control: ctl.removeAttribute("disabled")

To disable a control: ctl.setAttribute("disabled", "disabled")

Upvotes: 1

regex
regex

Reputation: 101

try this

if (radio1.checked == true)
        {
            var within = document.getElementById('<%=withinthepast.ClientID%>').enabled = false;
        }

you can add attributes clientIdMode = static

Upvotes: 1

Related Questions