Are you good at JavaScript? If so I need help!?
-
I am making a quiz where when you hit submit a JavaScript window pops up saying if you either correct or incorrect. Click on this link to see what i am talking about. http://peanutspace.com/chee/dropdown1.html as you can see that when you hit submit on each page the answer is always red. what i need help with is making the second page answer pop up that says the answer is green and the third as blue.. can any one help me? here is the JavaScript 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!"); document.getElementById('answer').valu… = ""; tooLate = 1; } } //array of right answers var ans=new Array(); ans[0]="green"; ans[1]="blue"; ans[2]="red"; function answer(question) { var correct = ans[2]; // 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(); function submitform() { document.forms["myform"].submit(); } } if you need the html code for reference just view source code on that link i posted Thank you!!
-
Answer:
The reason for this is found here: var correct = ans[2]; // This is the correct answer You specify which answer is correct. What you need to do is this: var correct = ans[x]; Now, for each question, you need to add a line like this BEFORE the linked script.js script: <script type="text/javascript"> var x = 2; // 2 for ketchup, 1 for sky, 0 for grass </script> Now, the linked script.js will inherit the value of x from your inline script on each page, thereby select the correct answer. I think this should solve your problem.
skateman... at Yahoo! Answers Visit the source
Related Q & A:
- I need help on what I need to buy or do.Best solution by Yahoo! Answers
- I need help with some horse questions, can you help me.Best solution by Yahoo! Answers
- I did something really bad and now i need help please help me.Best solution by Yahoo! Answers
- I need help with a song I heard.Best solution by Yahoo! Answers
- I need help buying a good video camera.Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.