...

View Full Version : Error:'lenght' is null or not an object



2insurepeople
10-26-2003, 04:19 AM
Dear Sir .
Please help me to correct this error
Line:40
char:11
Error:'lenght' is null or not an object
Code:0

I got this great script from>>
/***********************************************
* JavaScriptKit.com Multiple Choice Quiz Script (http://www.javascriptkit.com)
* Copyright 2003 JavaScript Kit- http://www.javascriptkit.com
* This notice and footnote must stay intact for use
* Visit JavaScript Kit (http://www.javascriptkit.com/) for full source code
***********************************************/
But when I changed the number to 20 ,There an error ,the script doesn't work

//Enter total number of questions:
var totalquestions=20
//Enter the solutions corresponding to each question:
var correctchoices=new Array()
correctchoices[1]='c' //question 1 solution
correctchoices[2]='a' //question 2 solution, and so on.

<<<<////>>>
correctchoices[20]='b'
/////Don't edit beyond here//////////////////////////

function gradeit(){
var incorrect=null
for (q=1;q<=totalquestions;q++){
var thequestion=eval("document.myquiz.question"+q)
for (c=0;c<thequestion.length;c++){
if (thequestion[c].checked==true)
actualchoices[q]=thequestion[c].value
}

if (actualchoices[q]!=correctchoices[q]){ //process an incorrect choice
if (incorrect==null)
incorrect=q
else
incorrect+="/"+q
}
}

if (incorrect==null)
incorrect="a/b"
document.cookie='q='+incorrect
if (document.cookie=='')
alert("Your browser does not accept cookies. Please adjust your browser settings.")
else
window.location="results.htm"
}


function showsolution(){
var win2=window.open("","win2","width=200,height=350, scrollbars")
win2.focus()
win2.document.open()
win2.document.write('<title>Solution</title>')
win2.document.write('<body bgcolor="#FFFFFF">')
win2.document.write('<center><h3>Solution to Quiz</h3></center>')
win2.document.write('<center><font face="Arial">')
for (i=1;i<=totalquestions;i++){
for (temp=0;temp<incorrect.length;temp++){
if (i==incorrect[temp])
wrong=1
}
if (wrong==1){
win2.document.write("Question "+i+"="+correctchoices[i].fontcolor("red")+"<br>")
wrong=0
}
else
win2.document.write("Question "+i+"="+correctchoices[i]+"<br>")
}
win2.document.write('</center></font>')
win2.document.write("<h5>Note: The solutions in red are the ones to the questions you had incorrectly answered.</h5><p align='center'><small><a href='http://www.javascriptkit.com' target='_new'>JavaScript Kit quiz script</a></small>")
win2.document.close()
}

Willy Duitt
10-26-2003, 05:31 AM
Hi;

Your eyes must be tired. :D

Look at your error message again. ;)

Please help me to correct this error
Line:40
char:11
Error:'lenght' is null or not an object

lenght should be length

......Willy

2insurepeople
10-26-2003, 03:20 PM
:o U right: :p But the Script still ERROR at this line >>

if (thequestion[c].checked==true)

Willy Duitt
10-26-2003, 04:03 PM
Hi 2insurepeople;

I really didn't think the problem could be that simple! :D

var thequestion=eval("document.myquiz.question"+q)

Where is your thequestion array?
Is the form name myquiz?
Are question +q spans?

Look in document.myquiz.question for the problem
If you can not find it, post that section of code as well.


.....Willy

glenngv
10-27-2003, 07:58 AM
the author should have not used the eval() method at all.
he could have used the form's elements array and the square bracket notation (http://www.litotes.demon.co.uk/js_info/sq_brackets.html).



function gradeit(){
var incorrect=null;
var thequestion;
for (q=1;q<=totalquestions;q++){
thequestion=document.myquiz.elements["question"+q];
for (c=0;c<thequestion.length;c++){
if (thequestion[c].checked==true)
actualchoices[q]=thequestion[c].value
}
...


As Willy said, you should check if your field names for questions are named question1, question2, ...questionN

2insurepeople
10-27-2003, 03:16 PM
:thumbsup: BIG Thank for Willy & glenngv

:o The Error solved:D :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum