Javascript errors in Mozila

Discussion in 'Javascript' started by Keith Bowes, Jan 9, 2004.

  1. Keith Bowes

    Keith Bowes Guest

    cwj wrote:
    > I have a form that I am validating. The script works fine in IE, but
    > Mozilla is a defferent story.
    >
    > Here is the section that is giving me problems.
    >
    > // Preferred contact method
    > if ((document.contact_form["contact_prefer"][0].checked == false)
    > && (document.contact_form["contact_prefer"][1].checked == false)) {
    > field_errors = field_errors+"Preferred contact method -
    > Please tells us how you would prefer to be contacted \n";
    > errors++;
    >
    > The Mozilla error reads:
    > document.contact_form["contact_prefer"][0] has no properties.
    >



    Do you have more than one form element with the name or id of
    "contact_prefer"? You can't do that in Mozilla. You'll need to use
    "contact_prefer0" and "contact_prefer1".
     
    Keith Bowes, Jan 9, 2004
    #1
    1. Advertising

  2. Keith Bowes

    cwj Guest

    I have a form that I am validating. The script works fine in IE, but
    Mozilla is a defferent story.

    Here is the section that is giving me problems.

    // Preferred contact method
    if ((document.contact_form["contact_prefer"][0].checked == false)
    && (document.contact_form["contact_prefer"][1].checked == false)) {
    field_errors = field_errors+"Preferred contact method -
    Please tells us how you would prefer to be contacted \n";
    errors++;

    The Mozilla error reads:
    document.contact_form["contact_prefer"][0] has no properties.

    Anyone know the answer to this one?

    Thanks
     
    cwj, Jan 9, 2004
    #2
    1. Advertising

  3. Keith Bowes

    Keith Bowes Guest

    HikksNotAtHome wrote:
    > In article <MyvLb.225$>, Keith Bowes
    > <> writes:
    >
    >
    >>>The Mozilla error reads:
    >>>document.contact_form["contact_prefer"][0] has no properties.
    >>>

    >>
    >>
    >>Do you have more than one form element with the name or id of
    >>"contact_prefer"? You can't do that in Mozilla. You'll need to use
    >>"contact_prefer0" and "contact_prefer1".

    >
    >
    > If Mozilla doesn't allow more than one form element to have the same name/id,
    > then its handling of radio buttons is busted:
    >
    > <form name="someName" action="someAction.something">
    > <input type="radio" name="myRadio" value="someValue1">Some Value 1
    > <input type="radio" name="myRadio" value="someValue2">Some Value 2
    > <input type="radio" name="myRadio" value="someValue3">Some Value 3
    > <input type="radio" name="myRadio" value="someValue4">Some Value 4
    > <input type="radio" name="myRadio" value="someValue5">Some Value 5
    > </form>
    >
    > The way that you "lock" radio buttons together is by the shared name attribute.


    You're right. It makes no sense whatsoever (I'm assuming JS does some
    sort of automatic type casting for this type of nonsense) but it works,
    even for text fields.
     
    Keith Bowes, Jan 9, 2004
    #3
  4. Keith Bowes

    Erwin Moller Guest

    cwj wrote:

    > I have a form that I am validating. The script works fine in IE, but
    > Mozilla is a defferent story.
    >
    > Here is the section that is giving me problems.
    >
    > // Preferred contact method
    > if ((document.contact_form["contact_prefer"][0].checked == false)
    > && (document.contact_form["contact_prefer"][1].checked == false)) {
    > field_errors = field_errors+"Preferred contact method -
    > Please tells us how you would prefer to be contacted \n";
    > errors++;
    >
    > The Mozilla error reads:
    > document.contact_form["contact_prefer"][0] has no properties.
    >
    > Anyone know the answer to this one?
    >
    > Thanks


    No, nobody knows that without the HTML.
    But this looks strange:
    document.contact_form["contact_prefer"][0]

    That is, to say the least, unconventional.
    I guess you are trying to read checkbox or radio.

    Better would be:
    document.forms["contact_form"].yourcheckboxnamehere[0].checked == false etc.

    Regards,
    Erwin Moller
     
    Erwin Moller, Jan 9, 2004
    #4
  5. cwj wrote:

    > I have a form that I am validating. The script works fine in IE, but
    > Mozilla is a defferent story.
    >
    > Here is the section that is giving me problems.
    >
    > // Preferred contact method
    > if ((document.contact_form["contact_prefer"][0].checked == false)
    > && (document.contact_form["contact_prefer"][1].checked == false)) {
    > field_errors = field_errors+"Preferred contact method -
    > Please tells us how you would prefer to be contacted \n";
    > errors++;
    >
    > The Mozilla error reads:
    > document.contact_form["contact_prefer"][0] has no properties.
    >
    > Anyone know the answer to this one?


    Maybe, next time show the HTML elements you try to script above, I
    suspect you have some
    <input type="radio"
    name="contact_prefer"
    id="contact_prefer"
    value="some value">
    <input type="radio"
    name="contact_prefer"
    id="contact_prefer"
    value="some other value">
    and unfortunately Mozilla has (had) a bug
    (http://bugzilla.mozilla.org/show_bug.cgi?id=183940) where then the
    access to the radio button array doesn't work as it used to in DOM 0
    browsers.
    I suggest you throw out the id attributes and use name attributes for
    the <input type="radio"> elements only, that should solve it. If you
    want to have an id attribute for your radio buttons then make the id
    unique for each radio and different from the name.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 9, 2004
    #5
  6. HikksNotAtHome wrote:

    > In article <MyvLb.225$>, Keith Bowes
    > <> writes:
    >
    >
    >>>The Mozilla error reads:
    >>>document.contact_form["contact_prefer"][0] has no properties.
    >>>

    >>
    >>
    >>Do you have more than one form element with the name or id of
    >>"contact_prefer"? You can't do that in Mozilla. You'll need to use
    >>"contact_prefer0" and "contact_prefer1".

    >
    >
    > If Mozilla doesn't allow more than one form element to have the same name/id,
    > then its handling of radio buttons is busted:
    >
    > <form name="someName" action="someAction.something">
    > <input type="radio" name="myRadio" value="someValue1">Some Value 1
    > <input type="radio" name="myRadio" value="someValue2">Some Value 2
    > <input type="radio" name="myRadio" value="someValue3">Some Value 3
    > <input type="radio" name="myRadio" value="someValue4">Some Value 4
    > <input type="radio" name="myRadio" value="someValue5">Some Value 5
    > </form>
    >
    > The way that you "lock" radio buttons together is by the shared name attribute.


    Yes, as long as you use the name attribute only you can have as many
    input elements with the same name as you like. And Mozilla doesn't have
    any problems with that.
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 9, 2004
    #6
  7. Keith Bowes

    cwj Guest

    Thanks for your help gang.

    Ended up I didn't need to validate those radio buttons after all, but
    you gave me lots to go on for the next time around.

    Thanks for all the quick responses. Hope I can be as helpful one day.

    CWJ


    On Fri, 09 Jan 2004 06:18:05 GMT, cwj <> wrote:

    >I have a form that I am validating. The script works fine in IE, but
    >Mozilla is a defferent story.
    >
    >Here is the section that is giving me problems.
    >
    >// Preferred contact method
    > if ((document.contact_form["contact_prefer"][0].checked == false)
    >&& (document.contact_form["contact_prefer"][1].checked == false)) {
    > field_errors = field_errors+"Preferred contact method -
    >Please tells us how you would prefer to be contacted \n";
    > errors++;
    >
    >The Mozilla error reads:
    >document.contact_form["contact_prefer"][0] has no properties.
    >
    >Anyone know the answer to this one?
    >
    >Thanks
     
    cwj, Jan 9, 2004
    #7
  8. cwj wrote:

    > The Mozilla error reads:
    > document.contact_form["contact_prefer"][0] has no properties.
    >
    > Anyone know the answer to this one?


    You have not shown the required snippets of the underlying markup, so
    guessing is all what is possible. Let us assume that "contact_form"
    is the name (i.e. the value of the "name" attribute) of a "form" element
    and you try to access the first form control named "contact_prefer".
    The proper, because standardized, way to access that control is

    document.forms["contact_form"].elements["contact_prefer"][0]

    This works, of course, only if there is more than one control of that
    name, otherwise there is no HTMLCollection object from which to retrieve
    the first item.


    HTH

    PointedEars
     
    Thomas 'PointedEars' Lahn, Feb 12, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mohan
    Replies:
    0
    Views:
    362
    Mohan
    Feb 13, 2006
  2. Mr. x
    Replies:
    7
    Views:
    620
    Richard Clark
    Dec 4, 2003
  3. Thom Little

    Firefox - Mozila - Netscape - Opera Rendering

    Thom Little, Jul 28, 2004, in forum: ASP .Net Web Controls
    Replies:
    11
    Views:
    319
    Dsyfa
    May 13, 2006
  4. Eitan
    Replies:
    1
    Views:
    108
    Martin Honnen
    Nov 28, 2004
  5. X t l a n

    document.body.clientWidth & Mozila<1.1

    X t l a n, Sep 1, 2005, in forum: Javascript
    Replies:
    0
    Views:
    93
    X t l a n
    Sep 1, 2005
Loading...

Share This Page