View Full Version : JavaQuiz- Changing the Questions
Suzzle
04-19-2004, 04:05 PM
Ok, i'll try and explain this as best as possible :o
Basically i have a multiple answer quiz which has been made using java, now i was wondering if there was any way of changing the questions and the answers on the site in the Admin section, so basically the admin can log in and update the quiz? Ive had a look about the net and cant seem to find anything, so was wondering if this was possible?
Cheers in advance
:thumbsup:
Garadon
04-19-2004, 06:04 PM
when you say Java do u then mean Java or JavaScript(this is a JavaScriptForum)
Presumable no matter which you can always change everything its really just a question of know where to change, and if u want help further than me telling u that u can change it, u migth wanna post a link to the quiz in question.
Suzzle
04-19-2004, 06:25 PM
Hi, Thanks for the reply
its a Javascript quiz ive done myself for a site im building.
What im 'hoping' to do is have a seperate login section for admin (which is done already) and then they can change/update the questions & answers for the quiz without changing it at the source....if that makes sence?
Garadon
04-19-2004, 08:41 PM
assuming ur quiz runs on some array as storage or something like that and that u got access to a server side language.
1 U could make an interface that writes in the js file
2 Make an interface that updates a db that, and have the array generated from that.
Suzzle
04-22-2004, 02:16 PM
Firstly i was gonna use asp, and have the whole quiz running from the database, but chose not to. At present there is no database connection what so ever to the quiz
<TD width="468" bordercolor="#CCCCCC"><font face="comic Sans MS">Frankies
Pet Shop is selling puppies for £12 each<br>
and baskets at £5 each<br>
Lucy would like to buy 2 puppies, one for her and one for her brother
and 2 baskets<br>
How much will it all cost?</font>
<input type="RADIO" name="q0" value="true">
or £26
<input type="RADIO" name="q0" value="false">
?</font>
and then goes onto :
<SCRIPT LANGUAGE="JavaScript"><!--
function validateAnswers() {
var correct = 0;
var wrong = 0;
var blank = 0;
for (var i=0;i<7;i++) {
var yesChoice = eval("document.Quiz1.q" + i + "[0].checked");
var noChoice = eval("document.Quiz1.q" + i + "[1].checked");
var yesAnswer = eval("document.Quiz1.q" + i + "[0].value");
var noAnswer = eval("document.Quiz1.q" + i + "[1].value");
if (yesChoice == noChoice)
blank++; // can't both be checked, thus must be both unchecked
else {
if ((yesChoice.toString() == yesAnswer) &&
(noChoice.toString() == noAnswer))
correct++;
else
wrong++;
}
}
document.Quiz1.correct.value = correct;
document.Quiz1.wrong.value = wrong;
document.Quiz1.blank.value = blank;
}
--></SCRIPT>
Im guessing either labeling the text areas where the questions needs to be changed, or connecting it to a databasE?
sad69
04-22-2004, 06:00 PM
I would say go the database route. It's cleaner and opens up more doors for the future of your application. You can have users logging in as well to keep track of their quiz results and see how they are progressing, etc.. even collecting statistics on your quizes.
For the admins: They can have a page which lists the questions and respective answers in textboxes which can be edited, and then saved. This updates the database.
For the user's quiz: You would just connect to the database and pull out the questions and answers and create your table and radio buttons and leave the Javascript on that page and it will work just like normal.
Suggestion: I don't know the nature of your quiz or its purpose, but if I were you, I wouldn't have Javascript score the quiz as if anyone looked at the source, they could easily cheat. If the radio choice is true, that's the correct answer, right? I guess it depends on your audience.. Anyway, I would have the user press a submit button once their quiz is complete and have your ASP score the page. Perhaps you can even re-display the quiz page showing the user's answers, the correct answers, and the solutions to the quiz questions (why they got it wrong...).
But using your current setup, you can't have your admins 'easily' change the questions and answers.
Also, when I first read your code about the two radios equaling eachother, I laughed and dreamt of the possibility of a user with 2 mice! But I quickly realized that you meant blanks.. lol
Good luck,
Sadiq.
Suzzle
04-22-2004, 06:28 PM
hmmm, thought a database conenction might be the case, yeah at present the users login to the site as well as admins, and the tracking their results was going to be a thing of the furute, but mite as well do it now.
I'm fine with the asp and connecting the database, but im a little confused with this part
and create your table and radio buttons and leave the Javascript on that page and it will work just like normal.
does that mean creating the radio buttons in the database, as in for example, radio button 1 & 2 as the attributes and then the answers as the value. or does the javascript create the radio buttons?
I did do this at first but i think i was going down the wrong route and getting confused with it, wasnt sure weather to have different tables for each seperate question, or just different tables for the different quiz's
which is why i went down the jave route.
All your suggestions have been great, and its inspired me now to stop being lazy and to do it this way, and as u said theres a lot that can be done with the quiz's this way!
I hope you dont mind but i sent you a pm as i was a little confused about that javascript part :)
Thank you for your help!
sad69
04-22-2004, 06:50 PM
I got your PM, and have responded to it..
But I'd prefer to keep it live on the forum. I think it's safe to say that this thread can be moved to the ASP forum now. It'll get more/better response there.
As for the quote in question, the ASP would generate the table and radio buttons based on your database. You should be able to do this with a loop. I didn't know how much ASP experience you've had, but you make it sound like you know what you're doing there, and with the database.
So basically, you query the database, grabbing the questions and answers. This is stored in some sort of recordset. You loop through the recordset and display the questions and radios accordingly.
Hope that makes some sense,
Sadiq.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.