0

I am trying to get a javascript function to work properly with my asp.net controls. I have two radio buttons and three textboxes.

When the first radio button is clicked I would like to disable the third textbox and when the second radio button is clicked I would like to disable the third text box. See the attachment for a screenshot.

I have tested that the function works by adding "OnClick" to the first radio button and setting AN ALERT WHICH IS WORKING.

However, I am not sure how to pass the controls in to the function to have access to them. Anyone know how to do this?

Screenshot enter image description here

ASP.NET

<asp:RadioButton ID="RadioButton1" runat="server" Checked="True" GroupName="DateTimeQuery" OnClick="TimeRangeClickEvent()"/>
<asp:TextBox ID="startdatetext" Enabled="true" runat="server" MaxLength="10"></asp:TextBox>
<asp:TextBox ID="enddatetext" Enabled="true" runat="server" MaxLength="10"></asp:TextBox>

<asp:RadioButton ID="RadioButton2" runat="server" GroupName="DateTimeQuery" OnClick="TimeRangeClickEvent() />
<asp:TextBox ID="withinthepast" Enabled="true" runat="server" Text="1"></asp:TextBox>

Javascript

<script>
        function TimeRangeClickEvent(How do I pass asp.net controls here)
        {
            alert('Working');            
        }
    </script>
0

1 Answer 1

1

You should use ClientID control properties to get IDs of HTML elements and then work with them from Javascript. More info.

In Javascript:

var radio1 = document.getElementById('<%=RadioButton1.ClientID%>');

When you have all your HTML elements you just need to handle necessary change/clicked/selected events in javascript to make it work.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep this will work. The only thing I had to add different as .checked at the end of the getElementByID to pass in the value whether the radio button was checked or not like this: var radio1 = document.getElementById('<%=RadioButton1.ClientID%>').checked; Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.