Javascript errors in Mozila

K

Keith Bowes

cwj said:
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".
 
C

cwj

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
 
K

Keith Bowes

HikksNotAtHome said:
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.[/QUOTE]

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.
 
E

Erwin Moller

cwj said:
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
 
M

Martin Honnen

cwj said:
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.
 
M

Martin Honnen

HikksNotAtHome said:
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.[/QUOTE]

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.
 
C

cwj

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
 
T

Thomas 'PointedEars' Lahn

cwj said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top