Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder Vincent Puglia's Avatar
    Join Date
    Jul 2003
    Location
    where the World once stood
    Posts
    367
    Thanks
    0
    Thanked 13 Times in 13 Posts
    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
    Where the world once stood
    the blades of grass
    cut me still

  • #3
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder Vincent Puglia's Avatar
    Join Date
    Jul 2003
    Location
    where the World once stood
    Posts
    367
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Hi Diane,

    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
    Where the world once stood
    the blades of grass
    cut me still

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Regular Coder
    Join Date
    Aug 2003
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Type "mocha" in the address bar, hit "enter", and let us know what the error message is.
    &nbsp;........ another wild guess ........

  • #7
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    Regular Coder
    Join Date
    Aug 2003
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do you have anything in the document set with a CSS 'position:absolute' (or 'relative')?
    &nbsp;........ another wild guess ........

  • #9
    Regular Coder Vincent Puglia's Avatar
    Join Date
    Jul 2003
    Location
    where the World once stood
    Posts
    367
    Thanks
    0
    Thanked 13 Times in 13 Posts
    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
    Where the world once stood
    the blades of grass
    cut me still

  • #10
    Regular Coder Vincent Puglia's Avatar
    Join Date
    Jul 2003
    Location
    where the World once stood
    Posts
    367
    Thanks
    0
    Thanked 13 Times in 13 Posts
    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
    Where the world once stood
    the blades of grass
    cut me still

  • #11
    Regular Coder
    Join Date
    Aug 2003
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ........

  • #12
    Regular Coder Vincent Puglia's Avatar
    Join Date
    Jul 2003
    Location
    where the World once stood
    Posts
    367
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Gee cheesebag,

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

    Vinny
    Where the world once stood
    the blades of grass
    cut me still

  • #13
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #14
    Regular Coder
    Join Date
    Aug 2003
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ........

  • #15
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •