Jump to content

Randomising form options


unplugged_web

Recommended Posts

I've got a form with radio buttons (I've used css to hid the buttons and show an image for the label), but I wondered if there was any way of randomizing the order of the options each time? So for question one it would be:1) A question: a) first answer:) second answerc) third answerd) fourth answere) fifth answerthen maybe next time it would be:1) A question: a) third answer:) fifth answerc) fourth answerd) first answere) second answerThe form is:Thanks for your help.

Link to comment
Share on other sites

you could keep all the questions answers in an array and randomize the number to use to access each the array's index.or (probably neater and easier to maintain)you could use a server side language and a DB, and then you could just use SQL RANDOM

Link to comment
Share on other sites

you could keep all the questions answers in an array and randomize the number to use to access each the array's index.or (probably neater and easier to maintain)you could use a server side language and a DB, and then you could just use SQL RANDOM
I think that using an array sounds the best way of doing it, because each question has different styles applied to them - unless I could store everything in the database? For example, I'd need to store:
<label for="answer2a" style="padding-left: 73px; padding-right: 74px;" onclick="className='active'; setTimeout('showhide(\'question2\',\'question3\')',1000)">first answer</label><input name="answer2" type="radio" value="A" id="answer2a" class="button1"/>

I'd certainly prefer to have everything stored in the database

Link to comment
Share on other sites

yup, make a table of questions, and a table of answers. Each answer is associated with a questions ID. You certainly wouldn't store the HTML/CSS/Javascript of course. With PHP you would construct a page with the appropriate HTML/CSS/Javascript while retrieving the relevant question and answer content from the DB.

Link to comment
Share on other sites

yup, make a table of questions, and a table of answers. Each answer is associated with a questions ID. You certainly wouldn't store the HTML/CSS/Javascript of course. With PHP you would construct a page with the appropriate HTML/CSS/Javascript while retrieving the relevant question and answer content from the DB.
I okay I think I've got that, just to check I thought I could do it like this;store the code (including the css as each answer has different css) for each answer, then using RAND() display the answers to the question - so each question has a table?
Link to comment
Share on other sites

you should just define the CSS when you write the PHP that generates the HTML. and by tables I meant tables in a database. I would use lists to organize the questions and answers.you should probably read the PHP/SQL tutorials so you get a better understanding of how they work with HTML/CSS and other things on the client side.

Link to comment
Share on other sites

you should just define the CSS when you write the PHP that generates the HTML. and by tables I meant tables in a database. I would use lists to organize the questions and answers.you should probably read the PHP/SQL tutorials so you get a better understanding of how they work with HTML/CSS and other things on the client side.
Thanks, I'll read those and then see how I get on. Thanks for your help.
Link to comment
Share on other sites

I decided to go down the database root and randomise everything that way. Thanks for the help :)
nice, you'll probably find it a lot easier to manage that way.
Link to comment
Share on other sites

If you have the Q's & A's in a DB then it might be an idea to have an array that you swap pointers (to Q's) over in a random way. I have used this method for a project I had on the laptop.Psudo code

Loop  myarray  a = random  b = random  swap = myarray(a)  myarray(a) = myarray(b)  myarray(b) = swapEnd loop

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...