Closed Bug 76049 Opened 23 years ago Closed 23 years ago

JS-based quiz always fails

Categories

(Core :: DOM: Core & HTML, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla0.9.6

People

(Reporter: spam, Assigned: jst)

References

()

Details

(Whiteboard: [HAVE FIX])

Attachments

(5 files)

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)
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: 
             http://www.dinside.no/ds/owa/ADMART_SPORO.sporsmal4 
             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
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:

                    document.formen.radio1[i]


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
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">
Finally: here is the function -

function leggInnData(formObj)
{
  data = new Array()
  antallSpor=1
  svartPaaAlle=0
  i=0

  while(typeof(document.formen.radio1[i]) == "object")
  {
    if (document.formen.radio1[i].checked)
    {
      svartPaaAlle = svartPaaAlle+1
      data[2]=document.formen.hRadio1.value
      data[1]=document.formen.radio1[i].value
    }

    i=i+1
  }

  formObj.aRadio.value = data

  if (svartPaaAlle>=antallSpor)
    formObj.submit()
  else 
    alert("Du må svare på alle spørsmålene. Prøv igjen!")
}
Phil, 
Thanks for the help. Can you create a small example that uses the JS that is 
causing the problem?
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla1.2
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
Since there are no longer any references to form submission in the 
reduced testcase, reassigning this to DOM component for consideration - 
Assignee: rods → jst
Status: ASSIGNED → NEW
Component: Form Submission → DOM Level 0
QA Contact: vladimire → desale
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
element....

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

while(typeof(document.formen.radio1[i]))
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.
Boris, the correct way of doing this would be:

  while(document.formen.radio1[i])

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.
Attached patch Proposed fixSplinter Review
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?
Hmm, I had completely forgotten about this bug, bz, care to review? jband, sr=?
Status: NEW → ASSIGNED
Whiteboard: [HAVE FIX]
Target Milestone: mozilla1.2 → mozilla0.9.6
Fabian, the attached fix should take care of all [] operator accessors in the DOM.
Comment on attachment 47718 [details] [diff] [review]
Proposed fix

sr=jband
Attachment #47718 - Flags: superreview+
r=fabian
(sorry bz, I figured i'd review it since it's nsDOMClassInfo and you're probably
still sleeping ;-)
Comment on attachment 47718 [details] [diff] [review]
Proposed fix

woops
Attachment #47718 - Flags: review+
Yep.  I was still sleeping.  Looks good and fixes this bug... r=bzbarsky, if
that's needed.  :)
Fixed.
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
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
http://www.dinside.no/page/artf/27164.shtml

As before click button "Ta testen" and fill in whatever till you're through and
the error occures.
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.

Attachment

General

Creator:
Created:
Updated:
Size: