Setting focus in a web form |
| |
|
|
|
New Coder
Location: USA
Gender:  Posts: 37 Topics: 3
|
|
|
August 05, 2010, 12:07:36 PM
|
|
This is a simple example for beginning web form designers.
When you build forms for online data submission you will often have a specific place where you want the user to start. For example, if I put together a form asking for a user’s first and last names I will usually start with the first name. That being the case why not guide my user to where they need to be and save them the extra step of selecting the first item in the process. We can do this by setting the form’s focus to the desired input field when the page loads. To accomplish this we need to add a line to the document’s body tag.
<body onLoad=”document. formname. inputname. focus()”>
Note: The above example assumes that the form’s name is set to “formname” and the input’s name is set to “inputname”. You can change those to match any naming convention you are using with your forms.
Anyway that’s all it takes. Now, when you load your page you should see that your focus is automatically set to the desired position.
|
|
| |
|
|
|
Regular Coder Posts: 50 Topics: 19
|
|
|
August 16, 2010, 09:13:47 PM
|
|
ASP.NET Web Form controls offer the appearance and functionality of the traditional HTML controls by generating the HTML elements on the client browser when the page is loaded. But unlike the HTML counterparts, ASP.NET Web Form controls provide a consistent and structured interface and more features, such as automatic postback, and the ability to generate multiple HTML elements from a single control. You can also use client-side scripting with these controls to provide additional functionality, such as setting the focus on an ASP.NET Web Form control.
« Last Edit: March 17, 2011, 10:22:29 PM by Admin »
|
|
| |
|
|
|
New Coder
Location: USA
Gender:  Posts: 37 Topics: 3
|
|
|
August 17, 2010, 06:41:35 AM
|
|
While all of that is indeed true, I'm not sure how it helps anyone looking in this section for Javascript examples. ;-)
|
|
| |
|
|
|
New Coder
Location: Australia
Gender: 
Age: 22
Posts: 42 Topics: 1
|
|
|
August 17, 2010, 05:28:55 PM
|
|
I'm with Wallynet on this one. Singam - please keep to the topic. While your statement on ASP is accurate, it's kind of not relevant when we're talking about JavaScript.
|
|
| |
|
|
|
Professional Coder Gender:  Posts: 242 Topics: 3
|
|
|
April 16, 2011, 06:36:14 AM
|
|
hmmmmm.. i think i kind of get it.. but I'm still confused..
|
|
| |
|
|
|
New Coder Posts: 25 Topics: 1
|
|
|
April 20, 2011, 09:09:35 PM
|
|
nice post.............
|
|
| |
|
|
|
Regular Coder Posts: 73 Topics: 2
|
|
|
August 06, 2011, 02:19:35 AM
|
|
There is one way:
In the .aspx file, add the onLoad attribute as in:
<body onLoad="document.forms[0].<%= TextBox.ClientID %>.focus();">
« Last Edit: August 11, 2011, 10:08:31 PM by Admin »
|
|
| |