473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 5517
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Csaba2000 | last post by:
I want to be able to programatically click on the center of an <INPUT type=image ...> element (I only care about IE 5.5+). This should work regardless of whether IE has focus. Normally you would...
22
by: DJ WIce | last post by:
Hi, I'm looking for a script to get the hi-est z-index on a page. I want my javascript menu to be always on top of the page (moves along on top when you scroll down). Does anyone know how to...
3
by: Praveen | last post by:
In IE a table element will receive focus when you either tab into it or when you click anywhere within the table. Mainly it fires the onfocus event. This doesn't happen in Mozilla (Firefox and...
10
by: tshad | last post by:
I have a page where I give focus to the first textbox on my page: <body onLoad="document.forms.firstName.focus();"> I also go and check the status of some data when I exit the 3rd textbox on...
3
by: Alex | last post by:
I am trying to insert Javascript code with grease monkey so it would insert to a page a call to a parent frame function al() I tried (portion of the code): x.document.createElement('script');...
2
dlite922
by: dlite922 | last post by:
Before traversing my code, here's what my goal is and what this function does: I have a table of fields that dynamically grows as the user enters information. A minimum of 3 rows must always...
3
by: blackrunner | last post by:
ERROR in my Query?! ERROR: Element GESCHLECHT is undefined in FORM. i think everything ok. Maby somebody can help me here Element GESCHLECHT is undefined in FORM. The error occurred...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.