469,923 Members | 1,199 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

Element Focus on Body load

Trying to set the focus to an element of input type on loading the page.
This is the code I used but it doesn't work. Any suggestions? (IE 6,
Windows)

<SCRIPT language=JavaScript>
funcion setFocus() {
document.formname.fieldname.onfocus();
}
</SCRIPT>

<BODY onload="setFocus()">

Thanks,
Mica
Jul 20 '05 #1
5 5415
Mica Cooper wrote:
Trying to set the focus to an element of input type on loading the page.
This is the code I used but it doesn't work. Any suggestions? (IE 6,
Windows)

<SCRIPT language=JavaScript>
funcion setFocus() {
document.formname.fieldname.onfocus();
}
</SCRIPT>

<BODY onload="setFocus()">

Thanks,
Mica

Well, the setFocus() routine should say
document.formname.fieldname.focus(), but why not just say that in the
onload statement?
Jul 20 '05 #2
Jerry,

Many thanks. I was using JavaScript Bible by Danny Goodman and it lists on
the bottom of page 66 document.formname.fieldname.onfocus();
as the proper way to give a field focus. Thank you for correcting me.

You are correct that I could do it in the onLoad but there are sometimes
more than one thing so I actually use and init() in the onLoad that would
call the setFocus method.

Thanks Again,
Mica Cooper

"Jerry Park" <No*****@No.Spam> wrote in message
news:Sm****************@bignews2.bellsouth.net...
Mica Cooper wrote:
Trying to set the focus to an element of input type on loading the page.
This is the code I used but it doesn't work. Any suggestions? (IE 6,
Windows)

<SCRIPT language=JavaScript>
funcion setFocus() {
document.formname.fieldname.onfocus();
}
</SCRIPT>

<BODY onload="setFocus()">

Thanks,
Mica

Well, the setFocus() routine should say
document.formname.fieldname.focus(), but why not just say that in the
onload statement?

Jul 20 '05 #3
@SM
Mica Cooper a ecrit :
Trying to set the focus to an element of input type on loading the page.
This is the code I used but it doesn't work. Any suggestions? (IE 6,
Windows)

<SCRIPT language=JavaScript>
funcion setFocus() {
document.formname.fieldname.onfocus();
// it is not 'onfocus' but 'focus'
document.forms['formname'].elements['fieldname'].focus();

}
onload=setFocus;

</SCRIPT>

<BODY onload="setFocus()">


onload in tag BODY is no more authorised (I think ...)
--
************************************************** ************
Stéphane MORIAUX : mailto:st*********************@wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
************************************************** ************
Jul 20 '05 #4
"Mica Cooper" <mi*********@microcore.net> writes:
Many thanks. I was using JavaScript Bible by Danny Goodman and it lists on
the bottom of page 66 document.formname.fieldname.onfocus();
as the proper way to give a field focus. Thank you for correcting me.


I would recommend using:
document.forms['formname'].elements['fieldname'].focus();
That is also correct according to the W3C DOM, as well as backwards
compatible with all (JS-enabled) browsers.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Hey backward compatibility.
I'll do that. Appreciate the tip.

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:is**********@hotpop.com...
"Mica Cooper" <mi*********@microcore.net> writes:
Many thanks. I was using JavaScript Bible by Danny Goodman and it lists on the bottom of page 66 document.formname.fieldname.onfocus();
as the proper way to give a field focus. Thank you for correcting me.
I would recommend using:
document.forms['formname'].elements['fieldname'].focus();
That is also correct according to the W3C DOM, as well as backwards
compatible with all (JS-enabled) browsers.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors:

<URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html> 'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by DJ WIce | last post: by
3 posts views Thread by Praveen | last post: by
10 posts views Thread by tshad | last post: by
3 posts views Thread by Alex | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.