JS-based quiz always fails

RESOLVED FIXED in mozilla0.9.6



DOM: Core & HTML
17 years ago
16 years ago


(Reporter: R.K.Aa., Assigned: jst)



Firefox Tracking Flags

(Not tracked)


(Whiteboard: [HAVE FIX], URL)


(5 attachments)



17 years ago
linux 20010414 and before

at http://www.dinside.no/side/a23379f.html there's a button-link to a quiz in
the middle table. "Ta testen!"
There are also former quiz'es listed below.
None of these ever worked in mozilla.
They obviously work in MSIE, and they work fine in NC4.*

To reproduce:

-go to http://www.dinside.no/side/a23379f.html
-click button "Ta testen!"
-On the resulting page - check any radiobutton and click the submit-button with
text "Neste"

Result: JS error in console:

JavaScript error: 
http://www.dinside.no/ds/owa/ADMART_SPORO.sporsmal4 line 367:
document.formen.radio1[i] has no properties

Expected: The page with next question to load (or a page saying the reply was wrong)

Comment 3

17 years ago
This site is extremely difficult to debug. So far, I have not been able
to find the line showing the error referred to above: 

             JavaScript error: 
             line 367:
             document.formen.radio1[i] has no properties

The submit-button with text "Neste" is as follows:

   <INPUT TYPE=button VALUE="Neste" onclick="leggInnData(this.form)">

However, so far I have not been able to find the function "leggInnData".
Summary: js based quiz always fails → JS-based quiz always fails

Comment 4

17 years ago
I'm going to defer this one to the Form Submission experts. It is almost
certainly not a problem with the JavaScript Engine. For some reason, when
the data is submitted to the server, the option buttons are undefined:


Is it because they are defined in a different form than the one doing
the submission? I don't know enough about this to make a good guess.

I did find this comment by jst from bug 37051:

   "I just checked in the fix for this, now form controls always have 
    their form as the script object parent and thus they're always in 
    the scope of the form they're associated with."

Reassigning to Form Submission for further analysis; cc'ing jst in case
there's something obvious that I've missed - 
Assignee: rogerl → rods
Component: Javascript Engine → Form Submission
QA Contact: pschwartau → vladimire

Comment 5

17 years ago
I can't get any debugging to work. For example, if I load the site
in NN4.7, the "Neste" submit button works as the reporter describes.
However, if I key this in the JavaScript Console: 

                   typeof document.formen.radio1

I get this error:  
                   JavaScript Error: [unknown origin]:
                   document.formen has no properties

Note: this is a form in the HTML:

                   <FORM name="formen">

Comment 6

17 years ago
Created attachment 31214 [details]
From Eric: HTML stream showing the function leggInnData()

Comment 7

17 years ago
Finally: here is the function -

function leggInnData(formObj)
  data = new Array()

  while(typeof(document.formen.radio1[i]) == "object")
    if (document.formen.radio1[i].checked)
      svartPaaAlle = svartPaaAlle+1


  formObj.aRadio.value = data

  if (svartPaaAlle>=antallSpor)
    alert("Du må svare på alle spørsmålene. Prøv igjen!")

Comment 8

17 years ago
Thanks for the help. Can you create a small example that uses the JS that is 
causing the problem?
Target Milestone: --- → mozilla1.2

Comment 9

17 years ago
Created attachment 32059 [details]
Reduced HTML testcase with the function leggInnData()

Comment 10

17 years ago
The reduced testcase works in NN4.7, but not in Mozilla. 

When you load it, click on the "Neste" button. In NN4.7, you will get an 
alert warning that you have not clicked any option button. Once you select 
an option button, you get an alert confirming that fact. There are no errors
in the JavaScript Console.

In Mozilla, no alert comes up in either case, and you get this error 
in the JavaScript Console. It is the original error reported above:

Error: document.formen.radio1[i] has no properties
Source File: http://bugzilla.mozilla.org/showattachment.cgi?attach_id=32059
Line: 36

Comment 11

17 years ago
Since there are no longer any references to form submission in the 
reduced testcase, reassigning this to DOM component for consideration - 
Assignee: rods → jst
Component: Form Submission → DOM Level 0
QA Contact: vladimire → desale

Comment 12

17 years ago
CC'ing bz, King of Debugging (TM). This is strange.
Phil, great testcase!

Here is the problem:

 while(typeof(document.formen.radio1[i]) == "object")

In mozilla, document.formen.radio1[3] is "null".  In NS 4.x it is "undefined".

In both browsers, typeof(undefined) is "undefined" and typeof(null) is "object"

So in mozilla we go through the loop for i=3 and naturally do not find such an

I would say this is evang. Nodes that don't exist are supposed to be "null",
right? The correct test that will work in either browser is


Comment 14

17 years ago
Er darn I had completely missed this one. Boris once again saved us. pschwartau,
do you think we should send this to evangelism? I don't think it's worth
changing on our side.

Comment 15

17 years ago
Boris, the correct way of doing this would be:


note, no typeof().

The strongest reason for supporting the array accessor syntax for our DOM arrays
is for backwards compatibility, thus array[x] should be undefined if there is no
'x' item in the array. array.item(x) should of course return null, as defined in
the DOM spec.

Patch coming up.

Comment 16

17 years ago
Created attachment 47718 [details] [diff] [review]
Proposed fix

Comment 17

17 years ago
jst, if we do this change wouldn't we want to do it for all [] operators of the
DOM Class Info?
we have a patch... This bug has been in limbo for months.  Is there any good
reason not to get this reviewed?
Keywords: 4xp, mozilla0.9.6, patch, review

Comment 19

17 years ago
Hmm, I had completely forgotten about this bug, bz, care to review? jband, sr=?
Whiteboard: [HAVE FIX]
Target Milestone: mozilla1.2 → mozilla0.9.6

Comment 20

17 years ago
Fabian, the attached fix should take care of all [] operator accessors in the DOM.

Comment 21

17 years ago
Comment on attachment 47718 [details] [diff] [review]
Proposed fix

Attachment #47718 - Flags: superreview+

Comment 22

17 years ago
(sorry bz, I figured i'd review it since it's nsDOMClassInfo and you're probably
still sleeping ;-)

Comment 23

17 years ago
Comment on attachment 47718 [details] [diff] [review]
Proposed fix

Attachment #47718 - Flags: review+
Yep.  I was still sleeping.  Looks good and fixes this bug... r=bzbarsky, if
that's needed.  :)

Comment 25

17 years ago
Last Resolved: 17 years ago
Resolution: --- → FIXED

Comment 26

17 years ago
it still fails, on the final page, where some "legg sammen" function is supposed
to "add together" the replies. Instead of producing a result page, i get a whole
page with former parameters, server info etc.

Old sample page is gone, but you can test with the "paranoia calculator" at

As before click button "Ta testen" and fill in whatever till you're through and
the error occures.

Comment 27

17 years ago
Testing with current cvs linux:
The quiz now completes flawlessly - no errors at any point.
You need to log in before you can comment on or make changes to this bug.