views:

47

answers:

4

Sorry but im an absolute noob with javascript.

Ive made a form for a simple quiz but cant figure out how to make radio's only click once.

I can select two or three buttons as my answer. i want to change this.

<form name = "Beginners Quiz">

<p>Film speed refers to:</p>
<p><input type="radio" name="Answer 1" id="Answer1" value = "a" onclick =  "recordAnswer(1,this.value"/>How long it takes to develop film. <br/>
<p><input type="radio" name="Answer 2" id="Answer2" value = "b" onclick = "recordAnswer(1,this.value"/>How fast film moves through film-transport system.  <br/>
<p><input type="radio" name="Answer 3" id="Answer3" value = "c" onclick = "recordAnswer(1,this.value"/> How sensitive the film is to light.  <br/>
<p><input type="radio" name="Answer 4" id="Answer4" value = "d" onclick = "recordAnswer(1,this.value"/> None of these makes sense. <br/>

ive been rooting around w3shcools tutorials to no avail. can someone shed some light?

+3  A: 

They should all have the same name attribute

eduffy
Damn those 2 seconds :)
Matt
+2  A: 

The name needs to be the same for all the radio buttons you want to act as a group.

Matt
+2  A: 

Try this

<p>Film speed refers to:</p>
<p><input type="radio" name="Answer" id="Answer1" value = "a" onclick =  "recordAnswer(1,this.value"/>How long it takes to develop film. <br/>
<p><input type="radio" name="Answer" id="Answer2" value = "b" onclick = "recordAnswer(1,this.value"/>How fast film moves through film-transport system.  <br/>
<p><input type="radio" name="Answer" id="Answer3" value = "c" onclick = "recordAnswer(1,this.value"/> How sensitive the film is to light.  <br/>
<p><input type="radio" name="Answer" id="Answer4" value = "d" onclick = "recordAnswer(1,this.value"/> None of these makes sense. <br/>
Ifi
A: 

Here's an approach... EDIT No Javascript needed, been awhile since I worked with radios.

In the body, you have this:

<form name="beginners_quiz">
<fieldset id="radios"><legend id="quiz">Film speed refers to:</legend>
<input type="radio" name="answer" id="Answer1" value="a" onclick="recordAnswer(1,this.value);" />How long it takes to develop film.<br/>
<input type="radio" name="answer" id="Answer2" value="b" onclick="recordAnswer(1,this.value);" />How fast film moves through film-transport system.<br/>
<input type="radio" name="answer" id="Answer3" value="c" onclick="recordAnswer(1,this.value);" />How sensitive the film is to light.<br/>
<input type="radio" name="answer" id="Answer4" value="d" onclick="recordAnswer(1,this.value);" />None of these makes sense.<br/>
</fieldset>
</form>

This should do it.

SoLoGHoST
no javascript is fine but do i not need javascript for the score function at the bottom?
OVERTONE
Sure, doing the `onclick event` will trigger the `recordAnswer function`. Though, honestly, I don't understand why you are using 1 as the first parameter in all 4 radios. Perhaps this has to do with something else, like the first question in the quiz. I'm assuming you already wrote the `recordAnswer` function? Sorry, I don't see any score function in your code above. If you are wanting to calculate the score automatically, you could use js, but you shouldn't have the answers to the questions in the source code of js script. Should be server-side IMO.
SoLoGHoST