SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    WebAmoeba mythix's Avatar
    Join Date
    Aug 2002
    Location
    here
    Posts
    578
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    document.forms[0] - idiot question

    I'm not a JS person, so hopefully this'll be nice an easy .

    The follwoing bit of code:
    Code:
    <script language="javascript">
    // if form exists , set cursor in first input field
    function focusonform()
    {
      if (document.forms[0]) {
    	document.forms[0].elements[0].focus();
    	} 
      else
    	{window.focus();}
    }
    </script>
    This appears to work fine on a page with no forms using Mozilla 1.0, IE6 on win2000. But NOT on IE6 on XP - I get the following message:

    A Runtime Error has occured.
    Do you wish to Debug?
    Line: 70
    Error: 'document.forms.0.elements.0'

    If UI start to debug it jumps to the "document.forms[0].elements[0].focus();" line. Presumably the misatke is in the "if (document.forms[0]) {".

    Can NE1 help???

    thanks
    Laws are like sausages. You have much more respect for them if you haven't actually seen how they're made.

    http://www.webamoeba.co.uk

  2. #2
    WebAmoeba mythix's Avatar
    Join Date
    Aug 2002
    Location
    here
    Posts
    578
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ignore me, I have resolved it. Am using an OS CMS so hadn't really looked closely at the page, for some reason they have it setting up an empty form, so it should be:

    if (document.forms[0].elements[0])
    Laws are like sausages. You have much more respect for them if you haven't actually seen how they're made.

    http://www.webamoeba.co.uk


Bookmarks

Posting Permissions

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