Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

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

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

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,050
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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

  • #6
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    BIG Thank for Willy & glenngv

    The Error solved


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •