JavaScript - Multiple Choice Quiz: Adding Sound On Mouseover To Javascript
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. Similar TutorialsHi! 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 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 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> Ok, I'm working in dreamweaver cs4 I'm trying to make my links have a sound on mouseover. The tag for this is under the depreciated behaviour section. I tried it to test it. It added the following code to my link: Code: To View Full Product Line<br /> <a href="http://herbal-nutrition.net/yesifeelgood/products" target="_blank" onmouseover="MM_controlSound('play','document.test','sounds/Sound 378.mp3')">Click Here</a> <embed name="test" src="sounds/Sound 378.mp3" loop="false" autostart="false" hidden="true" width="0" height="0" enablejavascript="true"></embed> My only problem is that when this loads in a browser on mouseover it loads the window as a quicktime sound then directs to the link preview on the following link (the link where I added the sound is underneath the slideshow: http://www.designfoxmediaworks.com/c...e/carlene.html is there something i should be changing to make this work properly? My code goes through the answer function (below) and it determins if you answered green. If you answered green a popup says correct other wise incorrect. How can I modify my code so that I can add multiple answers for different questions.Example q1 answer = green q2 answer = blue . . q20 answer = Friday Here is my .js code Code: var n = 16; // modify this for number of seconds to answer document.getElementById( 'time').value = "Answer in " + n + " seconds"; var i = setInterval('count()' , 1000); var tooLate; function count() { tooLate = 0; n--; if(n >=0) { document.getElementById( 'time').value = "Answer in " + n + " seconds"; } else { clearInterval(i); alert("Too late!"); if(document.getElementById( 'answer').value == correct){ tooLate = 1; } } function answer() { var correct = "green"; // This is the correct answer if (tooLate == 0) { if(document.getElementById( 'answer').value == correct) { clearInterval(i); alert("Right Answer with " + n + " seconds remaining"); } else{ clearInterval(i); alert("Incorrect! The answer was " + correct); } } submitform(); //submit form function submitform() { document.forms["myform"].submit(); } } Hey guys, I need some help. I have divs placed in a html document, and what I need to do is have a sound play when a person is to hover their mouse over the,. I used this code that I've butchered together from researching on the internet, but it just isn't working. The sound plays automatically as soon as the site loads. Can you please help me? Here is my code: Code: <html> <head> <script> function EvalSound(soundobj) { var thissound= eval("document."+soundobj); thissound.Play(); } </script> <embed src="C.mp3" autostart=false width=0 height=0 name="C" enablejavascript="true"> <embed src="D.mp3" autostart=false width=0 height=0 name="D" enablejavascript="true"> </head> <link rel="stylesheet" type="text/css" href="NavTest.css"> <div id=red alt="#" onMouseOver="EvalSound('C')"></div> <div id=blue alt="#" onMouseOver="EvalSound('D')"></div> </html> Thank you! [: Sorry, maybe I should also mention that my knowledge of Javascript is NONE! :| hi i have the following code which works fine in IE but nothing happens in firefox. Code: <html> <bgsound id="sound"> <script> function PlaySound(url) { document.all.sound.src = url; } </script> <body> <a href="#"><img src="images/butters.jpg" onMouseOver="PlaySound('http://www.pacdv.com/sounds/sounds/sound38.mp3')" /></a> </body> </html> Any one know of any good ways to make sound work in firefox? ta Hi people ! I went to this page: http://www.javascriptkit.com/script/....shtml#current and I applied that script to my website, everything work perfectly. I only have a question about it: * What should I add to the code to avoid the sound activate even when I'm hovering over the margin of the image? * Would it be possible that the sound activate only when the mouse is hovered over the image and not the margin as well ? * Is the only solution; to insert every image in their own div and then letting the div handle the margin? this is the site www.blackbandanamovement.com the images I'm talking about are in the footer. thanks in advance I got this javascript Click sound effect to work - http://www.javascriptkit.com/script/...oundlink.shtml My question is how do I make it work on my iphone4 ? I tested the above site on my phone and there is no audio when I tap the screen. The html5 <audio> seems to work with my mobile device on this site - http://css-tricks.com/examples/SoundOnHover/ I am new to javascript thx Hi all, I am using the following script posted on this site: http://www.javascriptkit.com/script/...oundlink.shtml It works great, but I want to extend this script and mute the sound using a checkbox. This checkbox has the id: sound. If checked, I want to hear the sounds, when unchecked, no sounds should be heard. This is the code I currently have for the checkbox: Code: function playSound() { if (document.getElementById('sound').checked){ -something needs to be added here to make it work?- } } Anyone have an idea how to make this work? Many thanks 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 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 am facing an issue where a link on my website opens in a new window if you simply click on it. However, if you right click and say open in new window or new tab, it opens the same window (URL) again from where the link is clicked. Self Service Option is a link and the JSP calls a function getSelfServSite() when the link is clicked. This is how the code flows in my case function getSelfServSite() { getToTheLink("${myConfigInfo.selfServiceURL}"); // this is because the URL is configurable } function getToTheLink(url) { window.open (url, "currentWindow", ""); } What am I doing wrong. I want it to go to the right link no matter how the user click it. Please advise. Thanks hi there, im trying to get a sound effect to play when a slideshow runs. the user selects the sound from a drop down menu on each image. The sound play when selected. But i need some way to pass it into the function that starts the slideshow. I am using pixtastic library to add effects to the images, and jquery (with cycle plugin) to perform the slideshow. The sounds ive put in work when selected, but i need to write a function to play them when the slideshow runs (this is where im stuck!) The library is soundmanager2 Here is the code 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"> <head> <script type="text/javascript" src="js/pixastic.core.js"></script> <script type="text/javascript" src="js/pixastic.jquery.js"></script> <script type="text/javascript" src="js/actions/sepia.js"></script> <script type="text/javascript" src="js/actions/flipv.js"></script> <script type="text/javascript" src="js/actions/emboss.js"></script> <script type="text/javascript" src="js/actions/blur.js"></script> <script type="text/javascript" src="js/actions/solarize.js"></script> <script type="text/javascript" src="js/actions/edges.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <!-- include Cycle plugin --> <script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script> <script type="text/javascript" src="js/Soundmanager/script/soundmanager.js"></script> <script> function change_image(id, effect) { Pixastic.process(document.getElementById(id),effect); } function startShow() { //get the canvas elements on the page var canvases = document.getElementsByTagName("canvas"); var viewpane = document.getElementById("slideshow"); for(i=0;i<canvases.length;i++) { viewpane.appendChild(canvases[i]); } $('#slideshow').cycle({ fx: 'all' // choose your transition type, ex: fade, scrollUp, shuffle, etc... }); } </script> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="css/main.css" type="text/css" /> <title>My Slideshow</title> </head> <body> <div> <!-- soundManager appends "hidden" Flash to the first DIV on the page. --> </div> <div class="wrap"> <h1 id="logo"><a href="javascript:location.reload(true)">My Slideshow!</a> <br /></a></h1> <ul id="menu"> Welcome to my slideshow, click view show to start<p>alternatively, click the headline to start again</p> </ul> <div id="text"> <h2>Edit the images and start the show!</h2><p><h3>You can add more than one effect to each image!</h3> <div id = "slideshow"> <iNPUT TYPE=BUTTON OnClick="startShow()" VALUE="View The Show"> </div> </div> <div id="leftcolumn"> <div id ="firstImage"> <img id="image1" src = "images/image1.jpg"></image> <form name="first_pic" id="first_pic"> <select name="image1" onchange = "change_image(this.name,this.value);"> <option value="blank">Edit the Image</option> <option value="sepia">Sepia</option> <option value="flipv">Flip Vertical</option> <option value="emboss">Emboss</option> <option value="solarize">Solarize</option> <option value="blur">Blur</option> <option value="edges">Edged</option> </select> <select name="image1" onchange = "soundManager.play(this.value);"> <option value="">Choose a sound</option> <option value="beep">Beep</option> <option value="gangsta">Gangsta</option> <option value="glass">Glass</option> <option value="page">Page turn</option> </select> </div> </p> </div> <div id="rightcolumn"> <div id = "secondImage"> <img id="image2" src = "images/image2.jpg"></image> <form name="first_pic" id="first_pic"> <select name="image2" onchange = "change_image(this.name,this.value);"> <option value="blank">Edit the Image</option> <option value="sepia">Sepia</option> <option value="flipv">Flip Vertical</option> <option value="emboss">Emboss</option> <option value="solarize">Solarize</option> <option value="blur">Blur</option> <option value="edges">Edged</option> </select> <select name="image2" onchange = "soundManager.play(this.value);"> <option value="">Choose a sound</option> <option value="beep">Beep</option> <option value="gangsta">Gangsta</option> <option value="glass">Glass</option> <option value="page">Page turn</option> </select> </div> </div> <div id="green_bubble"> </div> </div> <div id="footer"> <div class="wrap"> <div id="bubble"></div> <div id="copyright"> </div> <div class="clear"></div> </div> </div> <script type="text/javascript">soundManagerInit();</script> </body> </html> Thanks! first of all, heres my body code (dont mind the questions, theyre in greek): Code: <form name="htmltest" onSubmit="return check1() && check2() && check3() && check4() && check5() && check6() && results()"> <b>1) Τι σημαίνει HTML?</b><br> <input type="radio" name="q1" value="a" onclick="score[1]=0">a) Home Tool Markup Language<br> <input type="radio" name="q1" value="b" onclick="score[1]=0">b) Hyperlinks and Text Markup Language<br> <input type="radio" name="q1" value="c" onclick="score[1]=1">c) Hyper Text Markup Language<br> <b>2) Διάλεξε το σωστό HTML tag για την μεγαλύτερη επικεφαλίδα:</b><br> <input type="radio" name="q2" value="a" onclick="score[2]=0">a) < h6 ><br> <input type="radio" name="q2" value="b" onclick="score[2]=0">b) < head ><br> <input type="radio" name="q2" value="c" onclick="score[2]=1">c) < h1 ><br> <b>3) Ποιο είναι το σωστό HTML tag για line break?</b><br> <input type="radio" name="q3" value="a" onclick="score[3]=0">a) < break ><br> <input type="radio" name="q3" value="b" onclick="score[3]=0">b) < lb ><br> <input type="radio" name="q3" value="c" onclick="score[3]=1">c) < br ><br> <b>4) Διάλεξε το σωστό HTML tag για να κάνεις bold κάποια γράμματα:</b><br> <input type="radio" name="q4" value="a" onclick="score[4]=0">a) < bold ><br> <input type="radio" name="q4" value="b" onclick="score[4]=1">b) < b ><br> <input type="radio" name="q4" value="c" onclick="score[4]=0">c) < text.bold ><br> <b>5) Ποιος είναι ο σωστός τρόπος για να δημιουργήσετε έναν υπερσύνδεσμο;</b><br> <input type="radio" name="q5" value="a" onclick="score[5]=0">a) < a url="http://www.unipi.gr">Unipi.gr < / a><br> <input type="radio" name="q5" value="b" onclick="score[5]=1">b) < a href="http://www.unipi.gr">Unipi.gr< / a><br> <input type="radio" name="q5" value="c" onclick="score[5]=0">c) < a >http://www.unipi.gr"< / a><br> <b>6) Ποια απο τα παρακάτω HTML tag απευθύνονται όλα σε πίνακα?</b><br> <input type="radio" name="q6" value="a" onclick="score[6]=0">a) < table >, < head >, < tfoot ><br> <input type="radio" name="q6" value="b" onclick="score[6]=0">b) < table >, < tr >, < tt ><br> <input type="radio" name="q6" value="c" onclick="score[6]=1">c) < table >, < tr> , < td ><br> <input type="submit" value="Αξιολόγηση"> <input type="reset" value="Reset"><br><br> </form> and here's my javascript code Code: function check1() { var radio_choice=false; for (counter=0; counter < htmltest.q1.length; counter++) { if (htmltest.q1[counter].checked ) radio_choice=true; } if (!radio_choice) { alert("Παρακαλώ απαντήστε σε όλες τις ερωτήσεις") return (false); } return(true); } function check2() { var radio_choice=false; for (counter=0; counter < htmltest.q2.length; counter++) { if (htmltest.q2[counter].checked ) radio_choice=true; } if (!radio_choice) { alert("Παρακαλώ απαντήστε σε όλες τις ερωτήσεις") return (false); } return(true); } function check3() { var radio_choice=false; for (counter=0; counter < htmltest.q3.length; counter++) { if (htmltest.q3[counter].checked ) radio_choice=true; } if (!radio_choice) { alert("Παρακαλώ απαντήστε σε όλες τις ερωτήσεις") return (false); } return(true); } function check4() { var radio_choice=false; for (counter=0; counter < htmltest.q4.length; counter++) { if (htmltest.q4[counter].checked ) radio_choice=true; } if (!radio_choice) { alert("Παρακαλώ απαντήστε σε όλες τις ερωτήσεις") return (false); } return(true); } function check5() { var radio_choice=false; for (counter=0; counter < htmltest.q5.length; counter++) { if (htmltest.q5[counter].checked ) radio_choice=true; } if (!radio_choice) { alert("Παρακαλώ απαντήστε σε όλες τις ερωτήσεις") return (false); } return(true); } function check6() { var radio_choice=false; for (counter=0; counter < htmltest.q6.length; counter++) { if (htmltest.q6[counter].checked ) radio_choice=true; } if (!radio_choice) { alert("Παρακαλώ απαντήστε σε όλες τις ερωτήσεις") return (false); } return(true); } var score = new Array; function results() { var i, total; total = 0; for(i=1;i<=6;i++) { total += score[i]; } window=window.open("resultshtml.html","answers","width=400px,height=700px"); document.write(total); } what i want is, first of all an easier way to get an alert if not all questions are answered because mine (6 different functions) is a bit long. Also, when you press submit, a new window must pop up (not an alert box) with your score and the correct answers. I managed to get the window to pop up but i cant make it show the variable "total" value which contains the score (from the function "results"). Any ideas? Hello I need to make an answers page for a quiz but I don't know how to do it? Code is below if it helps Code: <!DOCTYPE html> <html> <head> <title>QUIZ</title> <script> var Q = function (id, text, correct, wrong) { this.id = id; this.text = text; this.correct = correct; this.wrong = wrong; this.answers = this.correct.concat(this.wrong) } Q.prototype = { blah: function () { document.write("<p>x<\/p>"); }, write: function () { if (this.asked) { return false; } this.asked = true; document.write( '<p>' + this.text + '<\/p>'); document.write( '<form>'); var type = ( this.correct.length > 1 ? "checkbox" : "radio" ); for (var i in this.answers) { document.write( '<input type="'+type+'" name="'+this.id+'">'+this.answers[i]+'<\/input><br>'); } document.write( '<\/form>'); return true; } } var questions = [ new Q( "Q1", "Question 1", ["Correct Answer"], ["Incorrect", "Incorrect", "Incorrect"] ), new Q( "Q2", "Question 2", ["Correct Answer", "Correct Answer"], ["Incorrect", "Incorrect", "Incorrect"] ), new Q( "Q3", "Question 3", ["Correct Answer", "Correct Answer"], ["Incorrect", "Incorrect", "Incorrect"] ), new Q( "Q4", "Question 4", ["Correct Answer"], ["Incorrect", "Incorrect."] ) ]; var askQuestions = function () { var asked = 0; while (asked < 3) { var num = Math.floor( Math.random() * questions.length ); var question = questions[num]; if (question.write()) { asked++; } } }; askQuestions(); </script> <BR> <input name="Submit" type="Submit" value="How did I do?"> </body> </html> Any suggestions? Thanks Hi, I am looking for a javascript quiz script that will allow me to grade individual sections of a quiz rather than grading the quiz as a whole. I am looking to setup an online test consisting of a number of sections but the output must grade each section individually. Any help apprecaited! Hello everyone, right now I have this in my site:
Code: <html> <head> <script type="text/javascript"> function open_win() { window.open("http://www.google.com/") window.open("http://www.google.com/") window.open("http://www.google.com/") window.open("http://www.google.com/") window.open("http://www.google.com/") window.open("http://www.google.com/") window.open("http://www.google.com/") window.open("http://www.google.com/") } </script> </head> <body> <form> <input type=button value="Open Windows" onclick="open_win()"> </form> </body> </html> And I was wondering if there's a way to get rid of the button, and make it so when the user opens the webpage, it automatically opens the multiple webpages. -- If that's not possible, I was also wondering if there's a way to make the button "click" on a mouseover, so when they move their mouse across the button, it opens the pages. I would rather have the 1st option, if possible. Thanks. |