Programming, website development forum Get latest updates by RSS Follow TechnicalTalk on Twitter Follow TechnicalTalk on Facebook 
HomeSearchRecent PostsLoginRegisterContact Us

Username  
Password    
  Forgot your password?  

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

Setting focus in a web form

 
webmaster forum
Wally  Offline
Activity
0%
 
New Coder
Location: USA
Gender: Male
Posts: 37
Topics: 3
WWW
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.

Totally-Gaming, when you really want to talk games.
 
webmaster forum
singam  Offline
Activity
0%
 
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 »
 
webmaster forum
Wally  Offline
Activity
0%
 
New Coder
Location: USA
Gender: Male
Posts: 37
Topics: 3
WWW
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.  ;-)

Totally-Gaming, when you really want to talk games.
 
webmaster forum
Activity
0%
 
New Coder
Location: Australia
Gender: Male
Age: 22
Posts: 42
Topics: 1
dexbydesign
WWW
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.
 
webmaster forum
Life Is Good!
Activity
0%
 
Professional Coder
Gender: Female
Posts: 242
Topics: 3
WWW
April 16, 2011, 06:36:14 AM

hmmmmm..  i think i kind of get it.. but I'm still confused..

Affordable Custom Web Design Services
 
webmaster forum
Activity
0%
 
New Coder
Posts: 25
Topics: 1
WWW
April 20, 2011, 09:09:35 PM

nice post.............

Nursing Assistant | Nursing Assistant Job | Nursing Assistant Salary
 
webmaster forum
netshet  Offline
Activity
6.67%
 
Regular Coder
Posts: 73
Topics: 2
WWW
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 »

hair transplant
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.15 | SMF © 2011, Simple Machines


Google visited last this page January 27, 2012, 09:51:54 PM