Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-26-2003, 04:19 AM   PM User | #1
2insurepeople
New to the CF scene

 
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
2insurepeople is an unknown quantity at this point
Error:'lenght' is null or not an object

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()
}
2insurepeople is offline   Reply With Quote
Old 10-26-2003, 05:31 AM   PM User | #2
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
Hi;

Your eyes must be tired.

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
Willy Duitt is offline   Reply With Quote
Old 10-26-2003, 03:20 PM   PM User | #3
2insurepeople
New to the CF scene

 
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
2insurepeople is an unknown quantity at this point
Unhappy

U right: But the Script still ERROR at this line >>

if (thequestion[c].checked==true)
2insurepeople is offline   Reply With Quote
Old 10-26-2003, 04:03 PM   PM User | #4
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
Hi 2insurepeople;

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

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
Willy Duitt is offline   Reply With Quote
Old 10-27-2003, 07:58 AM   PM User | #5
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
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.

Code:
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
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 10-27-2003, 03:16 PM   PM User | #6
2insurepeople
New to the CF scene

 
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
2insurepeople is an unknown quantity at this point
Smile

BIG Thank for Willy & glenngv

The Error solved
2insurepeople is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:54 PM.


Advertisement
Log in to turn off these ads.