navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
FrontPage Alternative
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

Set focus to any field you like in your form

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Community >> OutFront Discoveries >> Set focus to any field you like in your form
Page: [1]
 
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

(in reply to hhammash)
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

(in reply to hhammash)
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
======

(in reply to hhammash)
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

(in reply to hhammash)
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

(in reply to sgreen0)
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()" >

(in reply to sgreen0)
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

(in reply to hhammash)
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

(in reply to hhammash)
J-man

 

Posts: 936
From: Canada
Status: offline

 
RE: Set focus to any field you like in your form - 10/22/2002 1:08:58   
firstly, Doug G about your concern...
Yes it is cross compatible....
BUT make sure that this line:
<!-- Hide document.login.username.focus(); // -->

is sepatated into 3 different ones, like this:
<!-- Hide
document.login.username.focus();
// -->

Otherwise everything will be treated as comments and will not be executed.


[secondly] sgreen0,

Wont work for NN4 but here you go:

<html>
<head>
<script Language=" JavaScript" >
function setFocusAtEnd() {
document.MyForm.MyTextBox.focus();
document.MyForm.MyTextBox.value = document.MyForm.MyTextBox.value;
}
</script>
</head>
<body onload=" setFocusAtEnd()" >
<form name=" MyForm" >
<input name=" MyTextBox" type=" text" size=" 30" value=" Dear xxx" style=" width:240px; height:200px" >
</form>
</body>
</html>


[thirdly] your welcome :)

(in reply to hhammash)
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!


(in reply to hhammash)
J-man

 

Posts: 936
From: Canada
Status: offline

 
RE: Set focus to any field you like in your form - 10/22/2002 2:33:02   
quote:

Is it possible to have the script kick in only when the link to the script at the top of the page is clicked


the script kicks in because of body onload=" setFocusAtEnd()" >

if you set it so the function is ran with an onClick event it will work

if you want both body onload and onClick events to work together, you have two options that i could think of quickly
[1] use a javascript timer script so setFocusAtEnd thru body onload is initated after X amount of seconds OR then onClick is initiated

[2] use a javascript to check the scrol position of the user browsing the screen, if the position is near the form something like 0,700 then setFocusAtEnd when position 0,701 is reached, this would autoscroll the user to the for they are scrolling toward, and you can have the link href to the setFocusAtEnd focus as well

just a thought ~ sound good in theory do it :)
look over scripts here http://developer.irt.org/script/script.htm
You could probable piece something together, once you have tried you best goto a JS forum and hope for help. cheers

< Message edited by J-man -- 10/22/2002 2:50:24 AM >

(in reply to hhammash)
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

(in reply to hhammash)
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.

(in reply to hhammash)
J-man

 

Posts: 936
From: Canada
Status: offline

 
RE: Set focus to any field you like in your form - 10/22/2002 13:06:36   
id hate to mix orange juice and apple juice in a glass for drinking, so
here:
http://www.jguru.com/forums/home.jsp?topic=JavaScript

(in reply to hhammash)
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

(in reply to hhammash)
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

(in reply to hhammash)
Page:   [1]

All Forums >> Community >> OutFront Discoveries >> Set focus to any field you like in your form
Page: [1]
Jump to: 1





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