First of all, thanks for taking the time to read this. I'm super new to jquery and javascript and I'm trying to make a simple quiz.
I would like to let the user go back to the previous question. I have a button that they can click to go back. My idea was to hide the current question and show the previous one. For some reason, the program hides the current one, shows the previous one and then immediately opens the url again, appending the url with a question mark. So, it will basically open a new page, starting from the intro with the url "http://mydomain.com/quiz/?"
Here is my html:
And here is my javascript:HTML Code:<div id="intro"> <h1>Title here</h1> <p>A paragraph of intro text.</p> <button onclick="hideintro();">Click here to start the quiz!</button> </div> <form id="question1" action=""> <h2>Question 1</h2> <p>Question goes here.</p> <input type= "radio" onclick="answer1(1)" >First answer<br/> <input type= "radio" onclick="answer1(2)" >Second answer<br/> </form> <form id="question2" action=""> <h2>Question 2</h2> <p>Question goes here</p> <input type= "radio" onclick="answer2(1)" >answer 1<br> <input type= "radio" onclick="answer2(2)" >answer 2<br> <br/> <button onclick="goback(2);"><--Go back to previous question</button> </form> <script type="text/javascript" src="http://www.example.com/js/quiz.js"></script>
Now, be easy on me! I am a beginner and I am sure there are better ways I can do this. What I really want to know for now though is why my goback function ends up opening a whole new page and essentially starting the quiz over.Code:$("form").hide(); function hideintro() { $("#intro").hide(); $("#question1").fadeIn(); } function answer1(value) { if (value==1) { $("#question1").hide(); $("#question2").fadeIn(); } function answer2(value) { if (value==1) { $("#question2").hide(); $("#question3").show(); } function goback(currentquestion) { $("#question" + currentquestion).hide(); $("#question" + (currentquestion-1)).fadeIn(); }
Thanks...you guys rock!


Reply With Quote
Bookmarks