www.webdeveloper.com
Results 1 to 8 of 8

Thread: Please help asap with code!

  1. #1
    Join Date
    Apr 2012
    Posts
    4

    Please help asap with code!

    for some reason, my code does no submit the amount of answers or highlight the correct answers once submitted.

    code:

    <html>
    <head>
    <script = "javascript">
    document.write('<center><b><font color="#0000FF" font size=18>Binary Quiz</font></b></center>');
    document.write("<br clear=all>");

    document.write('This quiz is for those with the basic knowledge of Binary numbers, have fun and enjoy!');
    document.write("<br clear=all>");


    function show_alert()
    {
    alert("Think - binary, convert decimal numbers into binary first if it helps, for example, 1=?, 2=?, 3=0011");
    }
    </script>
    <script type="text/javascript">
    function myResult(){
    correctanswers = 0;
    if (document.myForm.q1[0].checked) correctanswers++;
    if (document.myForm.q2[1].checked) correctanswers++;

    document.getElementById("correct1").style.backgroundColor="red";
    document.getElementById("correct2").style.backgroundColor="red";

    return correctanswers;
    }

    function showResult(){
    clearInterval(clockId);
    correctAnswers2 = myResult();
    alert("You have answered" + correctAnswers2 + " answers correctly!");
    }
    </script>
    </head>
    <body>
    <input type="button" onclick="show_alert()" value="Hint" />
    <form name="myForm" action="">
    <center>

    <p>
    <IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />
    <input type="radio" name="q1" /> -1 <br />
    <input type="radio" name="q1" /> 0 <br />
    <input type="radio" name="q1" id="correct1"/> 1 <br />
    <input type="radio" name="q1" /> 2 <br />
    </p>
    <p>
    <IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />

    <input type="radio" name="q2" id="correct2"/> 5 <br />
    <input type="radio" name="q2" /> 8 <br />
    <input type="radio" name="q2" /> 9 <br />
    <input type="radio" name="q2" /> 4 <br />
    </p>
    <p>
    <input type="submit" name="submit" value="submit" onClick = "showResult()" />
    </p>

    </form>

    </body>
    </html>

    PLEASEEE HELP!

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Code:
    clearInterval(clockId);
    You're trying to clear a non-existent interval. Use the error console.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  3. #3
    Join Date
    Nov 2011
    Posts
    64
    I don't think "id" can put in radio button.

  4. #4
    Join Date
    Apr 2012
    Posts
    4

    Updated code.

    Now it all works but as soon as i add more than four questions it stops working. and the calculation of how many answers are correct do not calculate correctly. here is the code that works with four questions:

    <html>
    <head>
    <script = "javascript">
    document.write('<center><b><font color="#0000FF" font size=18>Binary Quiz</font></b></center>');
    document.write("<br clear=all>");

    document.write('This quiz is for those with the basic knowledge of Binary numbers, have fun and enjoy!');
    document.write("<br clear=all>");


    function show_alert()
    {
    alert("Think - binary, convert decimal numbers into binary first if it helps, for example, 1=?, 2=?, 3=0011");
    }


    function myResult(){
    correctanswers = 0;
    if (document.myForm.q1[0].checked) correctanswers++;
    if (document.myForm.q2[1].checked) correctanswers++;
    if (document.myForm.q3[2].checked) correctanswers++;
    if (document.myForm.q4[3].checked) correctanswers++;


    document.getElementById("correct1").style.backgroundColor="yellow";
    document.getElementById("correct2").style.backgroundColor="yellow";
    document.getElementById("correct3").style.backgroundColor="yellow";
    document.getElementById("correct4").style.backgroundColor="yellow";

    return correctanswers;
    }

    function showResult(){

    correctAnswers2 = myResult();
    alert("You have answered" + correctAnswers2 + "answers correctly!");
    }
    </script>
    </head>
    <body>
    <input type="button" onclick="show_alert()" value="Hint" />
    <form name="myForm" action="">
    <center>

    <p>
    <IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />
    <input type="radio" name="q1" /> -1 <br />
    <input type="radio" name="q1" /> 0 <br />
    <input type="radio" name="q1" id = "correct1"/> 1 <br />
    <input type="radio" name="q1" /> 2 <br />
    </p>
    <p>
    <IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />

    <input type="radio" name="q2" id = "correct2"/> 5 <br />
    <input type="radio" name="q2" /> 8 <br />
    <input type="radio" name="q2" /> 9 <br />
    <input type="radio" name="q2" /> 4 <br />
    </p>
    <p>
    <IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><br />

    <input type="radio" name="q3" id = "correct3"/> 10 <br />
    <input type="radio" name="q3" /> 8 <br />
    <input type="radio" name="q3" /> 4 <br />
    <input type="radio" name="q3" /> 5 <br />
    </p>
    <p>
    <IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><br />

    <input type="radio" name="q4" /> 7 <br />
    <input type="radio" name="q4" /> 11 <br />
    <input type="radio" name="q4" /> 14 <br />
    <input type="radio" name="q4" id = "correct4"/> 15 <br />
    </p>


    <p>
    <input type="button" value="Submit" onClick = "showResult()" />
    </p>

    </form>

    </body>
    </html>

    and this is the code when i add more than four questions which does not work at all!::

    <html>
    <head>
    <script = "javascript">
    document.write('<center><b><font color="#0000FF" font size=18>Binary Quiz</font></b></center>');
    document.write("<br clear=all>");

    document.write('This quiz is for those with the basic knowledge of Binary numbers, have fun and enjoy!');
    document.write("<br clear=all>");


    function show_alert()
    {
    alert("Think - binary, convert decimal numbers into binary first if it helps, for example, 1=?, 2=?, 3=0011");
    }


    function myResult(){
    correctanswers = 0;
    if (document.myForm.q1[0].checked) correctanswers++;
    if (document.myForm.q2[1].checked) correctanswers++;
    if (document.myForm.q3[2].checked) correctanswers++;
    if (document.myForm.q4[3].checked) correctanswers++;
    if (document.myForm.q5[4].checked) correctanswers++;
    if (document.myForm.q5[5].checked) correctanswers++;
    if (document.myForm.q5[6].checked) correctanswers++;
    if (document.myForm.q5[7].checked) correctanswers++;
    if (document.myForm.q9[8].checked) correctanswers++;
    if (document.myForm.q10[9].checked) correctanswers++;
    if (document.myForm.q11[10].checked) correctanswers++;
    if (document.myForm.q12[11].checked) correctanswers++;

    document.getElementById("correct1").style.backgroundColor="yellow";
    document.getElementById("correct2").style.backgroundColor="yellow";
    document.getElementById("correct3").style.backgroundColor="yellow";
    document.getElementById("correct4").style.backgroundColor="yellow";
    document.getElementById("correct5").style.backgroundColor="yellow";
    document.getElementById("correct6").style.backgroundColor="yellow";
    document.getElementById("correct7").style.backgroundColor="yellow";
    document.getElementById("correct8").style.backgroundColor="yellow";
    document.getElementById("correct9").style.backgroundColor="yellow";
    document.getElementById("correct10").style.backgroundColor="yellow";
    document.getElementById("correct11").style.backgroundColor="yellow";
    document.getElementById("correct12").style.backgroundColor="yellow";

    return correctanswers;
    }

    function showResult(){

    correctAnswers2 = myResult();
    alert("You have answered" + correctAnswers2 + "answers correctly!");
    }
    </script>
    </head>
    <body>
    <input type="button" onclick="show_alert()" value="Hint" />
    <form name="myForm" action="">
    <center>

    <p>
    <IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />
    <input type="radio" name="q1" /> -1 <br />
    <input type="radio" name="q1" /> 0 <br />
    <input type="radio" name="q1" id = "correct1"/> 1 <br />
    <input type="radio" name="q1" /> 2 <br />
    </p>
    <p>
    <IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />

    <input type="radio" name="q2" id = "correct2"/> 5 <br />
    <input type="radio" name="q2" /> 8 <br />
    <input type="radio" name="q2" /> 9 <br />
    <input type="radio" name="q2" /> 4 <br />
    </p>

    <p>
    <IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><br />

    <input type="radio" name="q3" id = "correct3"/> 10 <br />
    <input type="radio" name="q3" /> 8 <br />
    <input type="radio" name="q3" /> 4 <br />
    <input type="radio" name="q3" /> 5 <br />
    </p>
    <p>
    <IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><br />

    <input type="radio" name="q4" /> 7 <br />
    <input type="radio" name="q4" /> 11 <br />
    <input type="radio" name="q4" /> 14 <br />
    <input type="radio" name="q4" id = "correct4"/> 15 <br />
    </p>
    <p>
    <IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />

    <input type="radio" name="q5" /> 13 <br />
    <input type="radio" name="q5" /> 8 <br />
    <input type="radio" name="q5" id = "correct5"/> 9 <br />
    <input type="radio" name="q5" /> 5 <br />
    </p>

    <p>
    <IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><br />

    <input type="radio" name="q6" /> 10 <br />
    <input type="radio" name="q6" id = "correct6"/> 11 <br />
    <input type="radio" name="q6" /> 13 <br />
    <input type="radio" name="q6" /> 6 <br />
    </p>

    <p>
    <IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><br />

    <input type="radio" name="q7" /> 3 <br />
    <input type="radio" name="q7" id = "correct7"/> 2 <br />
    <input type="radio" name="q7" /> 10 <br />
    <input type="radio" name="q7" /> 5 <br />
    </p>

    <p>
    <IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><br />

    <input type="radio" name="q8" /> 11 <br />
    <input type="radio" name="q8" /> 14 <br />
    <input type="radio" name="q8" /> 12 <br />
    <input type="radio" name="q8" id = "correct8"/> 13 <br />
    </p>

    <p>
    <IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><br />

    <input type="radio" name="q9" /> 13 <br />
    <input type="radio" name="q9" /> 16 <br />
    <input type="radio" name="q9" id = "correct9"/> 11 <br />
    <input type="radio" name="q9" /> 3 <br />
    </p>

    <p>
    <IMG SRC=Game\0.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><br />

    <input type="radio" name="q10" /> 5 <br />
    <input type="radio" name="q10" /> 14 <br />
    <input type="radio" name="q10" /> 8 <br />
    <input type="radio" name="q10" id = "correct10"/> 4 <br />
    </p>

    <p>
    <IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><IMG SRC=Game\0.jpg><br />

    <input type="radio" name="q11" id = "correct11"/> 12 <br />
    <input type="radio" name="q11" /> 11 <br />
    <input type="radio" name="q11" /> 1 <br />
    <input type="radio" name="q11" /> 2 <br />
    </p>

    <p>
    <IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\1.jpg><IMG SRC=Game\0.jpg><br />

    <input type="radio" name="q12" /> 15 <br />
    <input type="radio" name="q12" /> 3 <br />
    <input type="radio" name="q12" id = "correct12"/> 14 <br />
    <input type="radio" name="q12" /> 10 <br />
    </p>

    <p>
    <input type="button" value="Submit" onClick = "showResult()" />
    </p>

    </form>

    </body>
    </html>

  5. #5
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    Radha123, do us a favor, use # for posting your code
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  6. #6
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by Radha123 View Post
    Now it all works but as soon as i add more than four questions it stops working. and the calculation of how many answers are correct do not calculate correctly.
    Incredibly you're still ignoring the error console. I hope you don't drive... [ Check Engine ]
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  7. #7
    Join Date
    Apr 2012
    Posts
    4
    use what error console? i dont know what that is LOL.
    im new to this ! sorry!

  8. #8
    Join Date
    Nov 2010
    Posts
    1,084

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles