Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My "onload" function is not working when viewed through Netscape 4

Status
Not open for further replies.

jaredc

Programmer
Jun 28, 2002
43
GB
Hi,

I've got a very simple piece of Javascript to set the focus onto a TEXT INPUT field as the page loads:
Code:
<!--
function focusSize()

{
document.frmQuantity.txtQuantity.focus();
}

-->
which I'm calling from the BODY tag as follows:
Code:
<body onload=&quot;focusSize()&quot;>
It works fine when the page is viewed through IE but not Netscape 4. This is not really a &quot;life or death problem&quot; but I would like to sort it out if possible. I had thought that maybe there's some other kind of 'onload' command which might be understood by netscape but am not really getting anywhere. Or maybe there's a problem with my javascript? Any thoughts or advice would be most welcome
 
Your code worked okay for me on Navigator 4.79.
Maybe add a &quot;;&quot; so that it reads <body onload=&quot;focusSize();&quot;>

Mickey
 
Hi Mickey

Thanks for the advice, and I'm glad to hear that it should be working in Netscape 4.79. I'm actually using Netscape 4.7 and I tried adding in the additional ; as advised but unfortunately no joy!

Cheers
Mike
 
There's no significant difference between the 2 Netscape sub-versions. What does the code for your form look like? I don't see anything wrong with the code you posted here.
 
Hi Trollacious
Thanks very much, your question has inspired me to sort out the problem myself! The code I'm using for the FORM is as follows:
Code:
Response.Write &quot;<FORM NAME=frmQuantity&quot; & lnCounter & &quot; ID=frmQuantity &quot; & lnCounter & &quot; METHOD=GET ACTION=&quot; & chr(34) & &quot;DisplayQuantity.asp&quot; & chr(34) & &quot;>&quot;
I'm including a counter on the FORM NAME/ID to enable a number of FORMs to be created as required. As such the name will never be called 'frmQuantity' and there will always be at least a 'frmQuantity0'. I've amended the Javascript to refer to 'frmQuantity0' and its working fine now (in both Netscape and IE). I'm not really sure how it was previously managing to work through IE though...

Hope this all makes (at least some) sense although it doesn't matter if it doesn't. Thanks once again and I feel a bit of an idiot for not spotting this before.
Cheers
Mike
 
If you have a txtQuantity element in each form, IE could well be ignoring the document.frmQuantity and just accessing the first txtQuantity element it encounters.
 
aha, thanks for that trollacious, clever old IE eh?
 
MikePasty,

you can also bypass the inconsistent form names and access it via index:

document.forms[0].txtQuantity.focus();

======================================

if (!succeed) try();
-jeff
 
Thanks very much for that also Jemminger, I'm learning all the time!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top