Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-25-2003, 04:17 PM   PM User | #1
dbast
New to the CF scene

 
Join Date: Sep 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
dbast is an unknown quantity at this point
Netscape onload focus tag works fine in IE, not in Netscape

I have a simple "email to a friend" form. When users get there, I want the cursor positioned in the first field of the form -- the FromName field.

The code works perfectly fine in IE 6. It will not work in Netscape Communicator 4.76. In Netscape, the cursor does not get positioned correctly and "JavaScript error" comes up at the bottom of the screen.

Seems to me this should be simple -- what am I doing wrong here?

<BODY onload="emailform.FromName.focus()">
__________________
--diane
dbast is offline   Reply With Quote
Old 09-25-2003, 04:27 PM   PM User | #2
Vincent Puglia
Regular Coder

 
Join Date: Jul 2003
Location: where the World once stood
Posts: 256
Thanks: 0
Thanked 2 Times in 2 Posts
Vincent Puglia is an unknown quantity at this point
Hi,

1) do you have form tags around the field? IE don't care, virtually everyone else does.
2)<BODY onload="document.emailform.FromName.focus()"> -- a full DOM path is required

Vinny
__________________
mod at WebXperts
Vincent Puglia is offline   Reply With Quote
Old 09-25-2003, 04:39 PM   PM User | #3
dbast
New to the CF scene

 
Join Date: Sep 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
dbast is an unknown quantity at this point
Vinny: Thanks for the quick reply.

Not sure what you mean by form tags around the field. This is a ColdFusion form, so I have <CFFORM> and </CFFORM> around the form itself, and <CFINPUT> tags around each field. Is it maybe the ColdFusion aspect that's giving me trouble?

I didn't have the full DOM path, but now do as you suggested. Still OK in IE, still not OK in Netscape.
__________________
--diane
dbast is offline   Reply With Quote
Old 09-25-2003, 04:59 PM   PM User | #4
Vincent Puglia
Regular Coder

 
Join Date: Jul 2003
Location: where the World once stood
Posts: 256
Thanks: 0
Thanked 2 Times in 2 Posts
Vincent Puglia is an unknown quantity at this point
Hi Diane,

Quote:
Is it maybe the ColdFusion aspect that's giving me trouble?
Quite possibly, but I don't know for sure. I presume the form is visible in NN4. Type 'javascript:' in the address bar and see what error message you are getting.

Vinny
__________________
mod at WebXperts
Vincent Puglia is offline   Reply With Quote
Old 09-25-2003, 05:00 PM   PM User | #5
Roy Sinclair
Senior Coder

 
Join Date: Jun 2002
Location: Wichita
Posts: 3,880
Thanks: 0
Thanked 0 Times in 0 Posts
Roy Sinclair will become famous soon enough
You used an IE proprietary shortcut which explains why it works in IE but not Netscape.

Try:

<BODY onload="document.forms.emailform.FromName.focus()">
__________________
Check out the Forum Search. It's the short path to getting great results from this forum.
Roy Sinclair is offline   Reply With Quote
Old 09-25-2003, 05:01 PM   PM User | #6
cheesebag
Regular Coder

 
Join Date: Aug 2003
Posts: 383
Thanks: 0
Thanked 0 Times in 0 Posts
cheesebag is an unknown quantity at this point
Type "mocha" in the address bar, hit "enter", and let us know what the error message is.
__________________
&nbsp;........ another wild guess ........
cheesebag is offline   Reply With Quote
Old 09-25-2003, 05:11 PM   PM User | #7
dbast
New to the CF scene

 
Join Date: Sep 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
dbast is an unknown quantity at this point
Thank you all -- maybe now we're getting somewhere?

I typed javascript: into the address bar, as Vinny suggested, and got this:

JavaScript Error:
http://www.heartland.org/EmailFriend.cfm?artId=12909, line
185:

document.forms.emailform has no properties.


What kind of properties might it be looking for?

------

I also tried changing my onload tag to look as Roy suggested,
<BODY onload="document.forms.emailform.FromName.focus()">,
but that didn't help. (didn't hurt either, which is always a good thing.)
__________________
--diane
dbast is offline   Reply With Quote
Old 09-25-2003, 05:15 PM   PM User | #8
cheesebag
Regular Coder

 
Join Date: Aug 2003
Posts: 383
Thanks: 0
Thanked 0 Times in 0 Posts
cheesebag is an unknown quantity at this point
Do you have anything in the document set with a CSS 'position:absolute' (or 'relative')?
__________________
&nbsp;........ another wild guess ........
cheesebag is offline   Reply With Quote
Old 09-25-2003, 05:22 PM   PM User | #9
Vincent Puglia
Regular Coder

 
Join Date: Jul 2003
Location: where the World once stood
Posts: 256
Thanks: 0
Thanked 2 Times in 2 Posts
Vincent Puglia is an unknown quantity at this point
Hi Diane,

Is it common practice with coldFusion to put a document inside a document?

PHP Code:
<html>
......
<
body>
<
BODY onload="document.forms.emailform.FromName.focus()">
<
html>
<
head>
.... 
Vinny
__________________
mod at WebXperts
Vincent Puglia is offline   Reply With Quote
Old 09-25-2003, 05:26 PM   PM User | #10
Vincent Puglia
Regular Coder

 
Join Date: Jul 2003
Location: where the World once stood
Posts: 256
Thanks: 0
Thanked 2 Times in 2 Posts
Vincent Puglia is an unknown quantity at this point
I didn't look at all the code, but if you are writing the second 'body' somewhere up top, NN4 may be trying to execute the onload before the form is written. In which case, the form has no properties.

Try putting the ''document....focus()" just before the closing body tag:

<script language='javascript' type='text/javascript'>
document...focus()
</script>
</body>

Vinny
__________________
mod at WebXperts
Vincent Puglia is offline   Reply With Quote
Old 09-25-2003, 05:36 PM   PM User | #11
cheesebag
Regular Coder

 
Join Date: Aug 2003
Posts: 383
Thanks: 0
Thanked 0 Times in 0 Posts
cheesebag is an unknown quantity at this point
OK...your HTML is, well, a mess. Two body tags, two </head> tags, scripts stuck in between head #2 & body #2...eeesh. All that needs to be fixed. And all that 'dynamic' HTML output is completely off the map, no way to build a page.

Here's the focus thing: Navigator 4 generates a Layer object every time you use CSS to set an element to position:absolute/relative. Don't ask why, it's a miserable decision made back in 1997. Since you've set your <div ID="contentmiddlenav"> to position:absolute, the form inside it is now in a stinkin' layer, which means it's essentially in another window. Great.
Code:
<script language="javascript" type="text/javascript">
var Explorer4 = (document.all);
var Netscape6 = (document.getElementById);
var Netscape4 = (document.layers);

onload = function() 
{
if (Netscape4)
document.contentmiddlenav.document.emailform.FromName.focus();
else document.emailform.FromName.focus();
}
__________________
&nbsp;........ another wild guess ........
cheesebag is offline   Reply With Quote
Old 09-25-2003, 05:41 PM   PM User | #12
Vincent Puglia
Regular Coder

 
Join Date: Jul 2003
Location: where the World once stood
Posts: 256
Thanks: 0
Thanked 2 Times in 2 Posts
Vincent Puglia is an unknown quantity at this point
Gee cheesebag,

Glad you had the patience to read all the code. Guess I should have drunk some 'mocha'

Vinny
__________________
mod at WebXperts
Vincent Puglia is offline   Reply With Quote
Old 09-25-2003, 05:44 PM   PM User | #13
dbast
New to the CF scene

 
Join Date: Sep 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
dbast is an unknown quantity at this point
Thumbs up On target!

Vinny, your latest post was right on target!

You were right not to look at all the code -- I'm including templates and other Cold Fusion stuff that makes this a messy page to look at in source view.

But I put this code

<BODY onload="document.forms.emailform.FromName.focus()">

immediately after the form and the close of a series of If statements that help define who gets what kind of email. The onload tag is followed by a couple of Cold Fusion templates, then the </body> tag. It works swimmingly now.

Wanted to thank you all for this exchange. I'm new to CodingForums but will be back! Great help, and fast! Thanks again.
__________________
--diane
dbast is offline   Reply With Quote
Old 09-25-2003, 05:56 PM   PM User | #14
cheesebag
Regular Coder

 
Join Date: Aug 2003
Posts: 383
Thanks: 0
Thanked 0 Times in 0 Posts
cheesebag is an unknown quantity at this point
Diane...

Sorry to disappoint you, but putting that body tag inside the layer (in between the <div></div> tags) was what 'fixed' it. The onload handler then runs in the scope of the layer, not the main window. This is not the proper way to do it, but I'll leave it at that....
__________________
&nbsp;........ another wild guess ........
cheesebag is offline   Reply With Quote
Old 09-25-2003, 06:00 PM   PM User | #15
dbast
New to the CF scene

 
Join Date: Sep 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
dbast is an unknown quantity at this point
Cheesebag:

I'll work on the mess. Am building on CF templates others have written, and I know it's not a pretty site/sight!
__________________
--diane
dbast is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:24 PM.


Advertisement
Log in to turn off these ads.