We help IT Professionals succeed at work.
Get Started

Setting Textbox Focus based on Radio Button (ASP.NET C# Javascript)

Last Modified: 2013-12-17
I'm not very good with JavaScript (still learning).  I have an ASPX page that has 3 radio buttons, and a textbox associated with each radio button. When the user clicks a particular radio button, I want to set the focus to a certain textbox, and disable the other textboxes.

How could I do this using javascript and not posting back?

For instance, in the code below, if I select radCityState, I want the txtCity textbox to get focus and I want to disable txtOrgName and txtZip...
	<asp:RadioButton ID="radOrgName" Text="Search by Organization Name:" Checked="true" GroupName="radOrgSearchType" runat="server" />                        
	<asp:TextBox ID="txtOrgName" MaxLength="200" Width="200px" runat="server" />
	<asp:RadioButton ID="radCityState" Text="Search by City and State:" GroupName="radOrgSearchType" runat="server" />
	<asp:TextBox ID="txtCity" runat="server" />, 
	<asp:DropDownList ID="ddlStates" ForeColor="#666666" runat="server" />
	<asp:RadioButton ID="radZip" Text="Search by Postal Code:" GroupName="radOrgSearchType" runat="server" />
	<asp:TextBox ID="txtZip" MaxLength="5" runat="server" /> 
	<asp:Button ID="btnSearchOrgs" Text="Search" runat="server" onclick="btnSearchOrgs_Click" >

Open in new window

Watch Question
Chief Technology Ninja
Distinguished Expert 2020
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE