Results 1 to 8 of 8

Thread: Accessing form elements for Netscape 4.7

  1. #1

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Accessing form elements for Netscape 4.7

    I have some JavaScript that accesses an element in a form:

    window.document.forms[formID].elements[elementID].value

    Where formID contains the name of the form and elemntID contains the name of the element. This works fine with IE and newer versions of Netscape.

    How can I change this so it will work with Netscape 4.7? - I don't mind if I need to do a check for browser version and use a different code for the different browsers.

    Any help appreciated.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Make sure all form elements have both the the id and name properties set.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    Yes they are the same. But I'm not sure I have explained well enough...

    function resetFormField(formID,elementID,defaultText) {
    if (document.forms[formID].elements[elementID].value == defaultText) {
    document.forms[formID].elements[elementID].value = '';
    }
    }

    This javascript function is called by an onFocus event:
    <input type="text" name="textfield" id="textfield" value="Enter keywords here" onFocus="resetFormField('FreeTextSearch','textfield','Enter keywords here');">

    Works fine in IE and newer version of Netscape.

    Any ideas?

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yeah. Ignore NS 4 It's a terrible browser anyway.

    Is the function even called in NS4? Maybe it doesn't know the onFocus event. Use an onClick instead.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    I can't ignore NS4 (true it is a truely terrible browser) but unfortunately people still use it!

    I'll check if NS4 recognises the onFocus event. Can't use onClick for this particular instance.

    Thanks.

  6. #6

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    Just checked up and onFocus is available for IE4+ and NS3+ so that can't be it.

    I've got a feeling the problem is caused by the form and element name being created dynamically in the javascript code.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Very likely, yes. Have you tried with predefined ones?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Note also that NS on Mac never recognizes names that contain an underscore.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width