The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hybrid View

Javascript/Form problem

I am trying to make a trivia game for a project that i'm doing, and i'm having some troubles. I have 5 questions stored in arrays, the 5 answers stored in a different array and those 5 answers wrote out in another array. I have 5 text boxes, one displaying the questions and the other 4 displaying the multiple choices. I also have 4 submit buttons, one for a, b, c and d. Now i just need to make sure that the answer the user picks is the right one. I was thinking, if there was a way to tell which submit box is clicked, that i would do something along that line, but if any one has a better way to do it then cool. Here's my code:

var Q=new Array(5)
Q[0]="About what percent of Michigan is covered with forest?"
Q[1]="Shade from trees can cool the surrouding area by how many degrees?"
Q[2]="Well managed forests provide..."
Q[3]="The most common tree in Michigan is ..."
Q[4]="How many jobs does Michigan's forest support?"

In this case I would go for radio buttons in front of your answers. Give your radio button (HTML: <input type=radio>) the same name and id. Then put an onclick event on the radio button. When the user clicks on one of the radio buttons you can do a check. You would store the index of the correct answer in an array, in this way you can check whether the user clicked the correct answer.