JavaScript - Fill In The Blank And Multiple Choice Quiz
I was wondering if someone could help me? In my code below what if answers in question 2 were allowed to be in any order? Like: hips,body,knees or knees,hips,body and so on. How should I modify my code? Anyone please????
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Quiz</title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <script type="text/javascript"> var answer_list = [ ['False'], ['body,hips,knees'] // Note: No comma after final entry ]; var response = []; function getCheckedValue(radioObj) { if(!radioObj) return ""; var radioLength = radioObj.length; if(radioLength == undefined) if(radioObj.checked) return radioObj.value; else return ""; for(var i = 0; i < radioLength; i++) { if(radioObj[i].checked) { return radioObj[i].value; } } return ""; } function setAnswer(question, answer) { response[question] = answer; } function CheckAnswers() { var correct = 0; var resp, answ; for (var i = 0; i < answer_list.length; i++) { resp = response[i].toString(); resp = resp.toLowerCase(); answ = answer_list[i].toString(); answ = answ.toLowerCase(); //################################################################################################# if (resp == answ) { correct++; if(i==0){ document.forms[0].a1c.style.backgroundImage="url('correct.gif')"; document.forms[0].a1c.value = ""; } else{ document.forms[0].a1d.style.backgroundImage="url('correct.gif')"; document.forms[0].a1d.value = ""; } } else{ if(i==0){ document.forms[0].a1c.style.backgroundImage = "url('incorrect.gif')"; document.forms[0].a1c.value = " ANS: False. Position the head snugly against the top bar of the frame and then bring the foot board to the infant's feet."; } else{ document.forms[0].a1d.style.backgroundImage = "url('incorrect.gif')"; document.forms[0].a1d.value = " ANS: " + answ; } //################################################################################################### } } document.writeln("You got " + correct + " of " + answer_list.length + " questions correct!"); } </script> </head> <body> <form action="" method="post"> <div> <b>1. When measuring height/length of a child who cannot securely stand, place the infant such that his or her feet are flat against the foot board.</b><br /> <label><input type="radio" name="question0" value="True" />True</label> <label><input type="radio" name="question0" value="False" />False</label> <br /> <textarea rows="2" cols="85" name="a1c" style="background-repeat:no-repeat"></textarea> <br /> <b>2. When taking a supine length measurement, straighten the infant's <input type="text" name="question1_a" size="10" />, <input type="text" name="question1_b" size="10" />, and <input type="text" name="question1_c" size="10" />.</b> <br /> <textarea rows="2" cols="85" name="a1d" style="background-repeat:no-repeat"></textarea> <br /> <input type="button" name="check" value="Check Answers" onclick="setAnswer(0,getCheckedValue(document.forms[0].question0));setAnswer(1,[document.forms[0].question1_a.value,document.forms[0].question1_b.value,document.forms[0].question1_c.value]);CheckAnswers();" /> </div> </form> </body> </html> Similar TutorialsDoes anyone know how I can modify the code below to show a question that has more then one fill in the blank? For example: _____ is an attitude or behavior which leads another to do ________. Thank you. Code: <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"> var question_type=new Array(4) question_type[0]="mult"; question_type[1]="mult"; question_type[2]="blank"; question_type[3]="blank"; var questions=new Array(4) questions[0]="The words used to <u>describe</u> the manifestation of Jesus as Messiah of Israel, Son of God and Savior of the world are ..."; questions[1]="Which of these is not a symbol of the Holy Spirit?"; questions[2]="Human life must be respected and protected absolutely from the moment of ______."; questions[3]="_____ is an attitude or behavior which leads another to do evil."; var answers = new Array(4) answers[0]= "B"; //The Epiphany answers[1]= "C"; //Sunshine [water, fire, anointing] answers[2]="conception"; answers[3]="scandal"; var each_question = new Array(3) each_question[0]="<table width='98%' border='0'>" + "<tr>" + "<td colspan='2'>" + "<font face='Arial, Helvetica, sans-serif'>" + questions[0] + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%'>" + " " + "</td>" + "<td>" + " " + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='A'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "The creed" + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='B'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "The Epiphany" + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='C'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "The magisterium" + "</font>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='D'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "The Annunciation" + "</font>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + " " + "</td>" + "<td>" + "<img src='line_animation.gif' width='160' height='14' align='right'>" + "</td>" + "</tr>" + "</table>" + "</font>"; each_question[1]="<table width='98%' border='0'>" + "<tr>" + "<td colspan='2'>" + "<font face='Arial, Helvetica, sans-serif'>" + questions[1] + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%'>" + " " + "</td>" + "<td>" + " " + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='A'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "Water" + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='B'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "Fire" + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='C'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "Sunshine" + "</font>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='radio' name='choice' value='D'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "Anointing" + "</font>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + " " + "</td>" + "<td>" + "<img src='line_animation.gif' width='160' height='14' align='right'>" + "</td>" + "</tr>" + "</table>" + "</font>"; each_question[2] = "<table width='98%' border='0'>" + "<tr>" + "<td colspan='2'>" + "<font face='Arial, Helvetica, sans-serif'>" + questions[2] + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%'>" + " " + "</td>" + "<td>" + " " + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='text' name='text_field'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + " " + "</td>" + "<td>" + "<img src='line_animation.gif' width='160' height='14' align='right'>" + "</td>" + "</tr>" + "</table>" + "</font>"; each_question[3] = "<table width='98%' border='0'>" + "<tr>" + "<td colspan='2'>" + "<font face='Arial, Helvetica, sans-serif'>" + questions[3] + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%'>" + " " + "</td>" + "<td>" + " " + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + "<input type='text' name='text_field'>" + "</td>" + "<td>" + "<font face='Arial, Helvetica, sans-serif'>" + "</font>" + "</td>" + "</tr>" + "<tr>" + "<td width='28%' align='right'>" + " " + "</td>" + "<td>" + "<img src='line_animation.gif' width='160' height='14' align='right'>" + "</td>" + "</tr>" + "</table>" + "</font>"; var currentQuestion=0; var score=0; function writeEachQuestion() { if(currentQuestion==0){ top.bottom_right.document.open(); top.bottom_right.document.write("<center>" + "<h3>" + "<font face='arial, helvetica, verdana'>" + "Go get 'em," + " " + userName + "!" + "<br>" + "</h3>" + "Let's see how well" + "<br>" + "you know your faith!" + "</center>" + "</font>"); top.bottom_left.document.write(each_question[currentQuestion]); } else { top.bottom_left.document.write(each_question[currentQuestion]); top.bottom_right.document.open(); } } function swapper() { top.bottom_left.document.fish_first.src="next2.gif"; } function unswapper() { top.bottom_left.document.fish_first.src="next.gif"; } function checkQuestionType() { if (question_type[currentQuestion-1]=="mult"){ multChecker(); } else if (question_type[currentQuestion-1]=="blank") { textChecker(); } } function multChecker() { var answerValue=answers[currentQuestion-1]; var checkedIndex = -1; for(i=0; i < top.bottom_left.document.quiz_questions.choice.length; i++) { //if a radio button is checked, the variable checkedIndex is set to the value of that index number. if(top.bottom_left.document.quiz_questions.choice[i].checked){ checkedIndex = i; selected_answer = top.bottom_left.document.quiz_questions[checkedIndex].value; } } if (selected_answer==answerValue) { score++; //The angelTableCorrect() function runs(see below). angelTableCorrect(); //An alert pops up if nothing's checked, with a string telling the user to guess next time. } else if (checkedIndex==-1){ alert("Next time," + " " + userName + "," + " " + "take a guess!"); //Because I'm heartless, the user isn't given a second chance. If not guess was made, angelTableWrong() executes (see below). angelTableWrong(); } else { angelTableWrong(); } } function textChecker() { var answerValue=answers[currentQuestion-1]; //theWord represents the user's input. var theWord = top.bottom_left.document.quiz_questions.text_field.value; theWordLower=theWord.toLowerCase(); if(theWordLower==answerValue) { score++; angelTableCorrect(); } else if (theWord!=answerValue) { angelTableWrong(); } } function angelTableCorrect () { top.top_right.document.open(); top.top_right.document.write("<table align='left'>" + "<tr>" + "<td align='center'>" + "<font face='Arial'>" + "Right," + " " + userName + "!" + "<br>" + "You're" + " " + score + " " + "out of" + " " + currentQuestion + "</td>" + "<td>" + "<img src='angel_correct.gif'>" + "</td>" + "</tr>" + "</table>"); } function angelTableWrong () { top.top_right.document.open(); top.top_right.document.write("<table align='left'>" + "<tr>" + "<td align='center'>" + "<font face='Arial'>" + "Wrong," + " " + userName + "." + "<br>" + "You're" + " " + score + " " + "out of" + " " + currentQuestion + "</td>" + "<td>" + "<img src='angel_wrong.gif'>" + "</td>" + "</tr>" + "</table>"); } function writeBeginning() { top.bottom_left.document.clear(); top.bottom_left.document.open(); top.bottom_left.document.write("<html>" + "<head>" + "</head>" + "<body>" + "<form name='quiz_questions'>"); } //This function writes the concluding part of each quiz question table in the bottom_left frame, except for the last one. //The last one's Next button has to call a different function, so I wrote the next function to do that. function writeEnding(){ top.bottom_left.document.write("<img name='fish_first' src='next.gif' align='right' onMouseOver='top.top_left.swapper();' onMouseOut='top.top_left.unswapper();' onMouseUp='top.top_left.onNext();'>" + "</form>" + "</body>" + "</html>") } //This function writes the concluding part of the last question, which has a next button that calls a //different function. function writeEndingLast(){ top.bottom_left.document.write("<img name='fish_first' src='next.gif' align='right' onMouseOver='top.top_left.swapper();' onMouseOut='top.top_left.unswapper();' onMouseUp='top.top_left.writeMailTable();'>" + "</form>" + "</body>" + "</html>") } function writeMailTable(){ top.top_right.document.open(); top.top_right.document.write("<font face='arial, verdana, helvetica'>" + "<center>" + "Thank you for" + "<br>" + "taking the quiz," + " " + userName + "!" + "<br><br>" + "</center>"); top.bottom_right.document.open(); top.bottom_right.document.write("<font face='arial, verdana, helvetica'>" + "<center>" + "If you don't have questions" + "<br>" + "you'd like to have answered," + " " + "<a href='http://www.archden.org' target='_blank')>" + "return to the" + "<br>" + "Archdiocese of Denver home page." + "</a>" + "</center>"); top.bottom_left.document.open(); top.bottom_left.document.write("<font face='arial, verdana, helvetica'>" + "Do you have questions about this quiz," + " " + userName + "?" + " " + "<img src='angel_final.gif' align='right'>" + "Post them in" + " " + "<a href='http://www.archden.org/ubb' target='_blank')>" + "The Upper Room," + "</a>" + " " + "the online community of the Archdiocese of Denver, in the 'What Does the Church Teach About ...?' forum!"); } function onNext() { //Write a table to the_questions.htm that includes a variable for the new question. if(currentQuestion==3) { currentQuestion++; textChecker(); doTheMath(); top.bottom_left.document.open(); top.bottom_left.document.write("<font face='arial, verdana, helvetica'>" + "<center>" + "You got" + " " + "<b>" + finalPercent + "%" + "</b>" + " " + "of the questions right," + " " + userName + "!" + "<br>" + "Click on the 'Next' fish" + "<br>" + "one more time to find out" + "<br>" + "how to get answers for those questions you missed." + "</center>" + "</font>"); writeEndingLast(); } else { currentQuestion++; checkQuestionType(); writeBeginning(); writeEachQuestion(); writeEnding(); } } //The doTheMath function divides the score by 20, and that multiplies that value by 100 to come up //with a final percentage value. That is used in the string written at the end (in the above onNext function). function doTheMath(){ thePercent=score/4; finalPercent=thePercent*100; } </script> </head> <body bgcolor="#FFFFFF" onLoad="writeBeginning(); writeEachQuestion(); writeEnding();"> <img src="title.gif" width="371" height="109"> <script language="JavaScript"> </script> </body> </html> Hi everyone, I have a very simple fill-in-the-blank quiz that I would like to add a randomizer to. Right now, the quiz has 3 questions that are asked one at a time, in order. I want to increase this to 100 possible questions (that part I can do), but I want the script to randomly choose 10 of them to ask. Then once the person has taken the quiz, they would be able to try again with 10 new questions. The script is live he http://www.elearnfrenchlanguage.com/...verb-quiz.html I have a quiz with a randomizing script, but it's for multiple choice questions, and I don't know how to adapt it so that it works with my script. Here is the working quiz: http://french.about.com/library/week...frenchquiz.htm And here is the randomizing script: http://french.about.com/library/weekly/longquiz.js I'd be so grateful for any help. Hello all, Making a multiple choice quiz using Blue J. My task is to enable the user to add questions and answers. Replace and remove specific answers and questions. Print out all the questions and answers once they are finished. Then quit the program. The user will also need to be able to quit the program at anytime. I am having trouble understanding how i would go about doing this, i figured i would store all the questions using an array or array list? I am working with the quiz found below (Multiple Choice Quiz that is instantly graded/checked), and would like to add pictures to the questions and rollover sound effects. I have figured how to add the picture, but not the sound. Sound effects are played when added to the html section, but not when added to the javascript coding. I am alright with html and css, but not with javascript. Any help from the javascript experts would be appreciated. ********* Coding Example ********* <HTML> <HEAD> <TITLE>The JavaScript Source: Miscellaneous : Multiple Choice Quiz</TITLE> <META HTTP-EQUIV="The JavaScript Source" CONTENT = "no-cache"> <META NAME="description" CONTENT="Add a quiz to your Web page without using a server-side script. Easy to set-up. Questions and answers are stored in a multi-dimensional array format in an external file. The quiz is marked in real time, and once answered, questions are set to read-only. A summary of the users score is alerted at the end."> <META NAME="date" CONTENT="2005-12-27"> <META NAME="channel" CONTENT="Developer"> <META NAME="author" CONTENT="James Crooke"> <META NAME="section" CONTENT="Miscellaneous"> <style type="text/css"> <!-- .question { color:darkblue; font-size:14px; font-weight:bold; } --> </style> <script type="text/javascript"> <!-- /* This script and many more are available free online at The JavaScript Source :: http://javascript.internet.com Created by: James Crooke :: http://www.cj-design.com */ var useranswers = new Array(); var answered = 0; function renderQuiz() { for(i=0;i<questions.length;i++) { document.writeln('<p class="question">' + questions[i] + ' <span id="result_' + i + '"><img src="blank.gif" style="border:0" alt="" /></span></p>'); for(j=0;j<choices[i].length;j++) { document.writeln('<input type="radio" name="answer_' + i + '" value="' + choices[i][j] + '" id="answer_' + i + '_' + j + '" class="question_' + i + '" onclick="submitAnswer(' + i + ', this, \'question_' + i + '\', \'label_' + i + '_' + j + '\')" /><label id="label_' + i + '_' + j + '" for="answer_' + i + '_' + j + '"> ' + choices[i][j] + '</label><br />'); } } document.writeln('<p><input type="submit" value="Show Score" onclick="showScore()" /> <input type="submit" value="Reset Quiz" onclick="resetQuiz(true)" /></p><p style="display:none"><img src="correct.gif" style="border:0" alt="Correct!" /><img src="incorrect.gif" style="border:0" alt="Incorrect!" /></p>'); } function resetQuiz(showConfirm) { if(showConfirm) if(!confirm("Are you sure you want to reset your answers and start from the beginning?")) return false; document.location = document.location; } function submitAnswer(questionId, obj, classId, labelId) { useranswers[questionId] = obj.value; document.getElementById(labelId).style.color = "grey"; //disableQuestion(classId); showResult(questionId); answered++; } function showResult(questionId) { if(answers[questionId] == useranswers[questionId]) { document.getElementById('result_' + questionId).innerHTML = '<img src="correct.gif" style="border:0" alt="Correct!" />'; // I tried to make the background a different colour for the answer document.getElementById(questionId).style.border ='1px'; } else { document.getElementById('result_' + questionId).innerHTML = '<img src="incorrect.gif" style="border:0" alt="Incorrect!" />'; } } function showScore() { if(answered != answers.length) { alert("You have not answered all of the questions yet!"); return false; } questionCount = answers.length; correct = 0; incorrect = 0; for(i=0;i<questionCount;i++) { if(useranswers[i] == answers[i]) correct++; else incorrect++; } pc = Math.round((correct / questionCount) * 100); alertMsg = "You scored " + correct + " out of " + questionCount + "\n\n"; alertMsg += "You correctly answered " + pc + "% of the questions! \n\n"; if(pc == 100) alertMsg += response[0]; else if(pc >= 90) alertMsg += response[1]; else if(pc >= 70) alertMsg += response[2]; else if(pc > 50) alertMsg += response[3]; else if(pc >= 40) alertMsg += response[4]; else if(pc >= 20) alertMsg += response[5]; else if(pc >= 10) alertMsg += response[6]; else alertMsg += response[7]; if(pc < 100) { if(confirm(alertMsg)) resetQuiz(false); else return false; } else { alert(alertMsg); } } function disableQuestion(classId) { var alltags=document.all? document.all : document.getElementsByTagName("*") for (i=0; i<alltags.length; i++) { if (alltags[i].className == classId) { alltags[i].disabled = true; } } } var questions = new Array(); var choices = new Array(); var answers = new Array(); var response = new Array(); // To add more questions, just follow the format below. questions[0] = "1) JavaScript is ..." ; choices[0] = new Array(); choices[0][0] = "the same as Java"; choices[0][1] = "kind of like Java"; choices[0][2] = "different than Java"; choices[0][3] = "ther written part of Java"; answers[0] = choices[0][2]; ///////// THIS IS THE SECTION THAT I'M TRYING TO WORK ON ///////// // image works, but sound doesn't // questions[1] = "<a href='javascriptHTMLSound' id='dummyspan' // the smiley is actually a colon followed by a D as in "DHTML" onMouseOver='DHTMLSound('success.wav')'><img src='some_image.gif'></a>"; choices[1] = new Array(); choices[1][0] = "Play This" + "<a href='javascriptlaySound('success.wav')'>Play This</a>"; choices[1][1] = "objective"; choices[1][2] = "evil"; choices[1][3] = "object based"; answers[1] = choices[1][3]; ///////////////////////////////////////////////////////////////// questions[2] = "3) To comment out a line in JavaScript ..."; choices[2] = new Array(); choices[2][0] = "Precede it with two forward slashes, i.e. '//'"; choices[2][1] = "Precede it with an asterisk and a forward slash, i.e. '*/'"; choices[2][2] = "Precede it with an asterisk, i.e. '*'"; choices[2][3] = "Precede it with a forward slash and an asterisk, i.e. '/*'"; answers[2] = choices[2][0]; questions[3] = "4) JavaScript can only run on Windows"; choices[3] = new Array(); choices[3][0] = "True"; choices[3][1] = "False"; answers[3] = choices[3][1]; questions[4] = "5) Semicolons are optional at the end of a JavaScript statement."; choices[4] = new Array(); choices[4][0] = "True"; choices[4][1] = "False"; answers[4] = choices[4][0]; questions[5] = "strings are..."; choices[5] = new Array(); choices[5][0] = "strings, numbers, BooBoos, and nulls"; choices[5][1] = "strings, text, Booleans, and nulls"; choices[5][2] = "strings, numbers, Booleans, and nulls"; choices[5][3] = "strings, numbers, Booleans, and zeros"; answers[5] = choices[5][2]; // response for getting 100% response[0] = "Excellent, top marks!"; // response for getting 90% or more response[1] = "Excellent, try again to get 100%!" // response for getting 70% or more response[2] = "Well done, that is a good score, can you do better?"; // response for getting over 50% response[3] = "Nice one, you got more than half of the questions right, can you do better?"; // response for getting 40% or more response[4] = "You got some questions right, you can do better!"; // response for getting 20% or more response[5] = "You didn't do too well, why not try again!?"; // response for getting 10% or more response[6] = "That was pretty poor! Try again to improve!"; // response for getting 9% or less response[7] = "Oh dear, I think you need to go back to school (or try again)!"; //--> </script> </HEAD> <BODY BGCOLOR=#ffffff vlink=#0000ff > <script> function DHTMLSound(surl) { document.getElementById("dummyspan").innerHTML="<embed src='"+surl+"' hidden=true autostart=true loop=false>"; } </script> <script type="text/javascript"> <!-- renderQuiz(); //--> </script> </body></html> ********* I have also tried the following sound ideas, but none work "within" the javascript -- they do work when assigned to a button inside the html however... The trick is, I want to be able to display an image within the question, then mouseover a <span> of text or an image (preferrably NOT a link <a>) and have the sounds played as part of the choices for the question. For a slightly different purpose, I'm also interested in being able to have the correst answer (for more complicated quizes) appear beside the question, in a <div> if possible, rather than an alert, to give the solution / reasoning for the correct answer. Any help at all would be really appreciated. Hi! I'm trying to make a multiple choice quiz using javascript. I downloaded codes from http://www.javascriptkit.com/script/cut180.shtml But when I used it nothing comes up on the results (number of correct answer, number of wrong answer and percentage) as well as the solution box is empty. I tried it on Google Chrome and it says "Your browser does not accept cookies. Please adjust your settings." So I tried it in Safari because that's what we use in school and it doesn't work. The results and solution box is empty. I am guessing that problem is with cookies? Please help me. Here are my codes: - Quiz //Enter total number of questions: var totalquestions=10 //Enter the solutions corresponding to each question: var correctchoices=new Array() correctchoices[1]='a' //question 1 solution correctchoices[2]='d' //question 2 solution, and so on. correctchoices[3]='b' correctchoices[4]='b' correctchoices[5]='c' correctchoices[6]='b' correctchoices[7]='a' correctchoices[8]='c' correctchoices[9]='d' correctchoices[10]='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.close() } ______________________________________________________________ For Results <html> <head> <title>Instant Quiz Results</title> </head> <body bgcolor="#FFFFFF"> <p align="center"><strong><font face="Arial"> <script src="quizconfig.js"> </script>Quiz Results Summary</font></strong></p> <div align="center"><center> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td width="100%"><form method="POST" name="result"><table border="0" width="100%" cellpadding="0" height="116"> <tr> <td height="25" bgcolor="#D3FFA8"><strong><font face="Arial">Number Of Correct Questions:</font></strong></td> <td height="25"><p><input type="text" name="p" size="24"></td> </tr> <tr> <td height="17" bgcolor="#D3FFA8"><strong><font face="Arial">Wrong Questions:</font></strong></td> <td height="17"><p><textarea name="T2" rows="3" cols="24" wrap="virtual"></textarea></td> </tr> <tr> <td height="25" bgcolor="#D3FFA8"><strong><font face="Arial">Grade Percentage:</font></strong></td> <td height="25"><input type="text" name="q" size="8"></td> </tr> </table> </form> </td> </tr> </table> </center></div> <form method="POST"><div align="center"><center><p> <script> var wrong=0 for (e=0;e<=2;e++) document.result[e].value="" var results=document.cookie.split(";") for (n=0;n<=results.length-1;n++){ if (results[n].charAt(1)=='q') parse=n } var incorrect=results[parse].split("=") incorrect=incorrect[1].split("/") if (incorrect[incorrect.length-1]=='b') incorrect="" document.result[0].value=totalquestions-incorrect.length+" out of "+totalquestions document.result[2].value=(totalquestions-incorrect.length)/totalquestions*100+"%" for (temp=0;temp<incorrect.length;temp++) document.result[1].value+=incorrect[temp]+", " </script> <input type="button" value="Retake Quiz" name="B1" onClick="history.go(-1)"> <input type="button" value="Show Solution" name="B2" onClick="showsolution()"></p> </center></div> </form> </body> </html> Please help me. I've been trying to find out what is wrong with my codes for a week. Thanks in advance! Hello, I am currently making a multiple choice program in JS using 3 arrays, one to call the question, one to store the user answer and one to store the real answer. The answers will then be compared to find the score. I have done most of it, but am still having one problem, I am using prompts and when I call the question, only the text in the if statement "qArray[counter]" is actually showing on the prompt and not the actual question from the array and I wondered if anyone could help? Thanks <html> <head><B>Multiple Choice Quiz</B> </head> <body> <script language = 'JavaScript'> document.write('<br><br>This program allows multiple choice questions to be asked - once finished a calculation will total your score.<br>'); qArray = new Array(); qArray = ['What is the capital of England? London/Paris/Cardiff/Berlin', 'What is the capital of France? London/Paris/Cardiff/Berlin', 'What is the capital of Wales? London/Paris/Cardiff/Berlin', 'What is the capital of Germany? London/Paris/Cardiff/Berlin']; aArray = new Array(); aArray = ['London', 'Paris', 'Cardiff', 'Berlin']; //array of the answers counter = 0; NumberofQuestions = 4; score = 0; while (counter < NumberofQuestions){ if (counter == 0){ question1=prompt('qArray[counter]',''); } if (counter == 1){ question2=prompt('qArray[counter]',''); } if (counter == 2){ question3=prompt('qArray[counter]',''); } if (counter == 3){ question4=prompt('qArray[counter]',''); } counter++; } studentAnswers = new Array(); studentAnswers = [question1, question2, question3, question4]; //an array with the answers the student has inputted counter = 0; while (counter < NumberofQuestions){ if (studentAnswers[counter] == aArray[counter]){ score++; } counter++; } document.write ('You have finished the quiz, your total marks will be calculated.'); //inform student that they have finished document.write('You scored: ',score,' /4'); //prints the score to screen. </script> </body> </html> I have just used an Analysis Quiz tool (on this page http://javascript.about.com/library/blquizf.htm) to create a quiz which doesn't have right or wrong answers but adds the scores of the answers together. It all works nicely, HOWEVER I require 5 answers as opposed to the maximum of four which has been offered on this site. The (partial) code is: Code: var quiz = new Array(); var r = 0; var analPage = 'result.html'; quiz[r++] =('93726~71~1. How often do you have a drink containing alcohol?~Never~Once a month or less~2 to 4 times a month~2 to 3 times a week~0~3'); quiz[r++] =('48844~37~How many units of alcohol do you have on a typical day when you are drinking?~1-2~3-4~5-6~7-9~0~3'); I thought it would be straight forward and I could add another option at the end of each string and then change the scoring e.g. quiz[r++] =('93726~71~1. How often do you have a drink containing alcohol?~Never~Once a month or less~2 to 4 times a month~2 to 3 times a week~4 or more times a week~0~4'); but this didn't work ... please help! Thank you Hello, I am trying to figure out how to write a quiz that has one question per html page, then once the choice has been selected, it will go to another page and tally a total at the end. Can this be done? And if so, can you point me in the right direction to research? Thanks in advance, Tanya Thanks for reading. I believe this is a JavaScript question, but if not, let me know and I'll move to another heading. I'd like a script that would allow a user to complete a sentence in a maximum of 140 characters (we'll let Twitter set the standard) and then rotate each users output on the screen. I also need to capture a name and email address. Example: "A man is _______________" Name________________ Email ________________ Output (to be displayed and rotated above the form) A man is a friend. I believe a HTML form will capture the info, but I'm unclear on how to have the output and name appear on the same screen and rotate between responses. Many Thanks. Hey I got two text boxes one for start date and second for end date in that i want to fill text boxes according to Quarter of a year, as like if i put 1-4-2012 in first text box then in second text box values should be automatically 30-6-2012. So now tell me please how to do this ??????? Regards rajboy13 Contact me @ = rajboy13@gmail.com I've got a form that performs a calculation upon submit. I want it to perform a different calc depending on the choice from a drop down box in the form. Are there any examples of this? or can someone explain how i do it? thanks Hi, I've checked the boards and was unable to find something that matched the code that I have. The code basically uses radio buttons to populate results to a drop-down list depending on the radio button they choose. I'm having trouble figuring out where and how to add the redirection url for each of the value choices in the drop down. I was told something about using window.location('http://url.here') and then to populate the location parameter with the array value. Does this mean I have to redo my script or can another piece of code be added on to make it work. How do I alter my existing code? Thanks in advance for any help I can get: Code: <!DOCTYPE html> <html lang="en"> <head> <script type="text/javascript"> var services = new Array(); services['Tutoring'] = ['Grady', 'Holy Innocents', 'North Springs', 'Paideia', 'Riverwood', 'School Not Listed?']; services['Recording'] = ['John Doe']; function changechoice(choice) { var serviceList = services[choice]; changeSelect('service', serviceList, serviceList); document.getElementById('service').disabled = false; document.getElementById('service').onchange(); } function changeservice(serviceValue) { document.getElementById('output').innerHTML = serviceValue; return; } function changeSelect(fieldID, newValues, newOptions) { selectField = document.getElementById(fieldID); selectField.options.length = 0; if (newValues && newOptions) { for (i=0; i<newValues.length; i++) { selectField.options[selectField.length] = new Option(newOptions[i], newValues[i]); } } } </script> </head> <body> <table width="400" align="center" colspan="2" border="0" rowspan="2"> <tr> <td width="200" align="left"> Pick an option: </td> </tr> <td width="200"> <br> <ul> <input type="radio" name="choice" value="Tutoring" onclick="changechoice(this.value);"> Tutoring<br /> <input type="radio" name="choice" value="Recording" onclick="changechoice(this.value);"> Recording<br /> </ul> </td> <br> <td width="200" align="center" valign="top"> <br> <select name="service" id="service" onchange="changeservice(this.value);" disabled="disabled"> <option> -- Choose an Option -- </option> </select> </td> </table> </body> </html> Is an iframe the only way to embed a web page? I would like to embed a web page within a email but some users email clients do not support iframes.
Ok so I have a select box where the value must be passed via the form. If the users selects choice B or Choice C then I want a specific div to show. If they choose choice A then I want the div to hide or remain hidden. It should be hidden on page load. Code: <select name="Event_Type_ID"> <option value="1">Choice A</option> <option value="2">Choice B</option> <option value="3">Choice C</option> </select> <div id="showme"> Content to show if EITHER Choice B or C is chosen. Otherwise this div should be hidden. </div> Can anyone lead me in the right direction? Thanks! Hi, I have a web form that I'm creating and it has some expandable checkboxes that need to be restricted based on choice. This is my criteria: If someone chooses checkbox number 1, they cannot choose any other checkbox. If someone chooses checkbox number 2, they may also choose number 3 but not 1 or 4, they must also answer the question that appears below. If someone chooses checkbox number 3, they may also choose number 2 but not 1 or 4, they must also answer the question that appears below. If someone chooses checkbox number 4, they cannot choose any other checkbox, and must answer the questions that appears below. One more caveat: If checkbox number 2 is chosen, and they've filled in all three lines of the question below, I need for them to dynamically add more lines as needed. I have attached my web form so you can see what I've done. I've researched these options and tried code from various examples but I can't seem to get it to work. Does anyone know how to accomplish all of this? Thank you in advance! Hello All, I'm trying to find a script that would be able to do the following: The are two drop down boxes, the first one populating the second (state/county --> town) The first box is single choice, the second is multiple choice. I'm looking for a script that would be able to deal with generating the code for all possible values that could be chosen in the second drop down box. The drop down boxes are part of a form which allow people to search for educational courses within areas of a state/county. I've had a good root around the internet but am rapidly getting confused ... many thanks in advance. Si. I have a radio button that asks Does your URL exist or need to be purchased? and a drop down menu that lists different types of web projects (i.e. new website and website redesign). What I'm trying to achieve is, if the user selects that the URL exists, I would like the drop down menu option new website to be removed from the list. Form: Code: <form> <input type="radio" name="website_status" value="exists"/> Exists <input type="radio" name="website_status" value="purchase_required"/> Needs to be purchased <select name="projects"> <option></option> <option value="new_website">New Website</option> <option value="website_redesign">Website Redesign</option> </select> </form> JavaScript: [CODE] <script> window.onload = initForms; function initForms() { for (var i=0; i<document.forms.length; i++) { document.forms[i].onsubmit = function() {return validForm();} } } function validForm() { var inputarray = document.getElementsByTagName("input"); var selectarray = document.getElementsByTagName("select"); var textarea = document.getElementsByTagName("textarea"); if (inputarray[0].checked == true) { selectarray[0].remove(options[1]); return false; } </script> I've been experimenting with this for the last couple hours and am getting nothing! Could someone please point me in the right direction? What I would like to do is have a page with a dropdown menu, and depending on which option the user chooses from the dropdown, reload the page and display a particular iframe below the dropdown, based on the users choice. Also, a default iframe would load (the one connected to the default choice in the select box). Hopefully that makes sense. I was trying to make this work with PHP (without having the user having to click a submit button) but I couldn't find a way to make it happen.
|