|
| |
|
|
hhammash
Posts: 1064 Joined: 8/19/2002 Status: offline
|
Set focus to any field you like in your form - 9/29/2002 18:00:12
Set Focus to Any Field You Like When the User loads your Form This is a famous subject around the forums. When you pusblish your form to the Internet, you notice when you load it that no field gets the focus (i.e have the cursor positioned in the first field ready for user' s input). This is a useful trick: Type this link in the body tage, the whole body tag will look like this. <Body OnLoad=" javascript:FormName.FieldName.focus();" > FormName: is the name of your form, if you don' t have one, right click the form, select properties and name your form. FieldName: is the name of the field that you want it to get the focus. These are the only two things you need to change. Regards
|
|
|
|
Charles W Davis
Posts: 1725 Joined: 3/7/2002 From: Henderson Nevada USA Status: offline
|
RE: Set focus to any field you like in your form - 10/14/2002 16:29:05
Hisham, It works well on four of my sites. I' ll put it on more! Thanks for posting this"
_____________________________
Enjoy! It' s your endeavor! http://www.anthemwebs.com
|
|
|
|
Charles W Davis
Posts: 1725 Joined: 3/7/2002 From: Henderson Nevada USA Status: offline
|
RE: Set focus to any field you like in your form - 10/14/2002 16:43:03
Hisham, How do you combine body tags? I have a form on a page that has the following: <body onload=" dynAnimation()" > Thanks,
_____________________________
Enjoy! It' s your endeavor! http://www.anthemwebs.com
|
|
|
|
Doug G
Posts: 1189 Joined: 12/29/2001 From: SoCal Status: offline
|
RE: Set focus to any field you like in your form - 10/14/2002 17:38:10
I don' t know if it' s cross-browser compatible, but I put a script at the bottom of the html source to set the focus. <SCRIPT Language=" javascript" >
<!-- Hide
document.login.username.focus();
// -->
</SCRIPT>
This is just before the closing </body> tag
_____________________________
====== Doug G ======
|
|
|
|
sgreen0
Posts: 726 From: Long Beach, CA, USA Status: offline
|
RE: Set focus to any field you like in your form - 10/17/2002 16:36:20
I' d also like to know if it' s possible to include more than one onload function in the <body> tag. Thanks. Stephen
|
|
|
|
WantToLearn
Posts: 109 Joined: 10/19/2002 Status: offline
|
RE: Set focus to any field you like in your form - 10/19/2002 13:21:14
Here is one way to include more than one onload function in the <body> tag. Separate the functions with a semicolon. <body onload=" dynAnimation();FormName.FieldName.focus();" > Joe
|
|
|
|
WantToLearn
Posts: 109 Joined: 10/19/2002 Status: offline
|
RE: Set focus to any field you like in your form - 10/19/2002 13:45:30
Or... Another way is to create an onload function. I prefer this method when I have 2 or more items or functions that need to be run. It' s cleaner and easier to maintain. <head> <SCRIPT Language=" javascript" > <!-- function window_onLoad() { dynAnimation(); FormName.FieldName.focus(); FormName.FieldName2.select(); Formname.FieldName3.disabled=true } // --> </SCRIPT> </head> <body onload=" window_onLoad()" >
|
|
|
|
sgreen0
Posts: 726 From: Long Beach, CA, USA Status: offline
|
RE: Set focus to any field you like in your form - 10/19/2002 16:55:30
Thanks, WantToLearn! I tried the first method, but for some reason it didn' t work in my context. Creating the " window_onload" function works fine, though. Thanks again. Stephen
|
|
|
|
sgreen0
Posts: 726 From: Long Beach, CA, USA Status: offline
|
RE: Set focus to any field you like in your form - 10/19/2002 17:01:05
I just thought of another question. I would like to focus the cursor into a text box field. I have entered some text already (" Dear xxx" and two line feeds). Is there a way to focus the cursor into that text box at the END of the existing text so the user can just start typing?? Any ideas? Stephen
|
|
|
|
sgreen0
Posts: 726 From: Long Beach, CA, USA Status: offline
|
RE: Set focus to any field you like in your form - 10/22/2002 2:20:03
J-man! Thanks for your post. The code - setFocusAtEnd() - works fine. You can look at http://www.jacobschimes.com/contactus.htm. Now here' s where it really gets tricky. I have a form way way down on a page - http://www.jacobschimes.com/comments.htm. If I include setFocusAtEnd(), the page immediately scrolls down to the bottom to display the cursor in the form field. Is it possible to have the script kick in only when the link to the script at the top of the page is clicked? I guess if the user scrolls down on his own, he' ll have to click inside the form field himself... Thanks again. Stephen BTW, I' m originally from Toronto though I now live in Sunny California!
|
|
|
|
sgreen0
Posts: 726 From: Long Beach, CA, USA Status: offline
|
RE: Set focus to any field you like in your form - 10/22/2002 10:35:42
J-man! Thanks for your response. I guess I' m getting too picky. onClick would be perfect, but... I removed the onLoad event and I tried including an onClick event like this: <a href=" #Comment" onClick=setFocusAtEnd()></a> This doesn' t seem to work. Does the onClick rely on the onLoad being there? Thanks. Stephen
|
|
|
|
sgreen0
Posts: 726 From: Long Beach, CA, USA Status: offline
|
RE: Set focus to any field you like in your form - 10/22/2002 11:12:59
Sorry, that should be: <a href=" #Comment" onClick=setFocusAtEnd()>Here' s the link</a> S.
|
|
|
|
hhammash
Posts: 1064 Joined: 8/19/2002 Status: offline
|
RE: Set focus to any field you like in your form - 10/23/2002 13:30:36
Hi, Thank you all for your input. You made it a rich subject. Regards Hisham
|
|
|
|
sgreen0
Posts: 726 From: Long Beach, CA, USA Status: offline
|
RE: Set focus to any field you like in your form - 10/25/2002 16:20:35
This is what ended up working: <a href=" javascript:setFocusAtEnd(' Comment' )" >Here' s the link</a> That way the script kicks in only when the link is clicked! Thanks everyone. Stephen
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|