JS-based quiz always fails

RESOLVED FIXED in mozilla0.9.6

Status

()

Core
DOM: Core & HTML
RESOLVED FIXED
17 years ago
16 years ago

People

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

Tracking

Trunk
mozilla0.9.6
x86
Linux
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [HAVE FIX], URL)

Attachments

(5 attachments)

(Reporter)

Description

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

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:

                    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

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()
  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!")
}

Comment 8

17 years ago
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

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
Status: ASSIGNED → NEW
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
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]))

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.
(Assignee)

Comment 15

17 years ago
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.
(Assignee)

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
(Assignee)

Comment 19

17 years ago
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
(Assignee)

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

sr=jband
Attachment #47718 - Flags: superreview+

Comment 22

17 years ago
r=fabian
(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

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

Comment 25

17 years ago
Fixed.
Status: ASSIGNED → RESOLVED
Last Resolved: 17 years ago
Resolution: --- → FIXED
(Reporter)

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
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.
(Reporter)

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.