Hi all, I have the following codes currently to show the user's results once they answer the quiz: <SCRIPT LANGUAGE="JavaScript"> var ans = new Array; var done = new Array; var yourAns = new Array; var score = 0; ans[1] = "a"; ans[2] = "d"; ans[3] = "c"; ans[4] = "b"; ans[5] = "c"; ans[6] = "a"; ans[7] = "d"; function Engine(question, answer) { yourAns[question]=answer; } function Score(){ var answerText = "Quiz Results\n\n"; for(i=1;i<=7;i++){ answerText=answerText+"Q"+i+": "; if(ans[i]!=yourAns[i]){ answerText=answerText+"Wrong! The correct answer is "+ans[i]+". \n"; } else{ answerText=answerText+"Correct!\n"; score++; } } answerText=answerText+"\nYour score is "+score+" out of "+(i-1)+"! \n"; alert(answerText); } </script> Code (markup): My quiz questions are like: Q1) Question here<p> <input type=radio name="q1" value="a" onClick="Engine(1, this.value)"> a) answer a<br> <input type=radio name="q1" value="b" onClick="Engine(1, this.value)"> b) answer b<br> <input type=radio name="q1" value="c" onClick="Engine(1, this.value)"> c) answer c<br> <input type=radio name="q1" value="d" onClick="Engine(1, this.value)"> d) answer d<br><p> Code (markup): Currently, when I press the submit button, it prompts an alert box with the results..but as highlighted in another thread, I need to open a new window and display the results there Is there anyway that I can do so by passing the variables after the user clicks the submit button (at the same time when the Score() is executed)? Any help / advise is greatly appreciated. Thank you.
This probably can be done but I can see it causing problems with pop-up blockers. Why not use document write to print the result dynamically to the page at the end of the quiz?
Hi Dave487, In addition to the results, I also need to include a link so that user can link to a relevant section on that particular question (if he / she got it wrong). Printing all these at the end of the page is not as user friendly as opening another small window in my opinon. I have looked around for some alternatives, one is to do a window.open. I will try out and see what i can get.. By the way, I believe that the pop-up blocker won't block window.open, right?
By using window.open, you'll be able to modify the contents of the new window, or if the window.open is calling an existing page, then you'll be able to call functions in that page, so I agree that you should try it. Most pop-ups are as a result of window.open being called, so of course pop-up blockers will block them. The only thing you have to your advantage is that the user is initiating the window.open call (as opposed to the popups being called onload). Some pop-up blockers allow this, some don't, and other are configurable to block this.