SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Fort Lauderdale
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Older browsers, form syntax

    Can anyone tell me if code to access form elements is compatible with older browsers, particularly IE, NS, and AOL? I'm thinking about NS 4.5+, IE 4+, AOL 5+. Example:

    f = document.forms['formName'].elements;

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    These have nothing to do with browser object models - they're simply alternative ways of referencing any browser object:

    document.forms['formName'].elements;
    document.forms.formName.elements;

    Both reference the same object - the elements[] array of a form named 'formName' (imaginative), the first using hashtable referencing, the second, dot syntax. More here.

    As for whether you need to include the [document.]forms[] collection in the reference, I'd say emphatically 'no' - but some people get exercised when you espouse any form of shortcut referencing so, take your pick. The same applies to document.image_name, document.form_name.element_name, Select[n] (no options[] reference) and so on. These all work in the v.4+ browsers mentioned.
    ::: certified wild guess :::

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I actually prefer to use the hashtable references. Sometimes, forms and images aren't properly exposed as document properties (in some browsers) - and an XHTML-compatible form (one without a name attribute) won't register either. Using the collections removes all ambiguity.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •