开发者

making check boxes clickable once in javascript?

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>&l开发者_Python百科t;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?


They should all have the same name attribute


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


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/>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜