[thelist] JavaScript Quiz Problem: Wont Work in Netscape

Andrew Clover and at doxdesk.com
Fri Apr 19 06:03:01 CDT 2002


Annie <annie at twitch.ca> wrote:

> Anyone have any idea why this wont work in netscape?

Enter javascript: in the status line to see the console with any error
messages. Trying to click Submit results in:

  JavaScript Error: document.quiz.T1 is not a function

Indeed:

  if (document.quiz.T1(0).checked)

T1 is an array of inputs. You read an input from the array using the
array[index] syntax, not function(arguments). I'm amazed this ever worked
in any browser. Changing to square brackets fixes it.

BTW you could perhaps change that long script to something like:

var answers= 'bcabc';

function Evaluate() {
  var els= document.forms['quiz'].elements;
  var el, sel, ans, mark;
  for (var i= 0; i<answers.length; i++) {
    el= els['T'+(i+1)];
    sel= '';
    for (var j= 0; j<el.length; j++)
      if (el[j].checked) sel='abcdef'.charAt(j);
    if (sel!='') {
      ans= answers.charAt(i);
      mark= (sel==ans) ? 'check' : 'x';
      document.images['none'+(i+1)].src= ans+'-'+mark+'.gif';
  } }
}

which would allow you to add questions and answers more easily.

--
Andrew Clover
mailto:and at doxdesk.com
http://and.doxdesk.com/



More information about the thelist mailing list