By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,567 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,567 IT Pros & Developers. It's quick & easy.

Element Focus on Body load

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
@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

P: n/a
"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

P: n/a
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.