PDA

View Full Version : Script to take the value of ratio in a form



queentown
11-07-2007, 02:02 AM
I have a form contains like this:



<font color="#000000"><b><div>What is the color of the sky ?</div></b></font><br>
<input type="radio" name="q_0_1" id="q_0_1_0" value="0"onClick="onclickradio1();"><label for="q_0_1_0"><font color="#3366FF">Blue</font></label> <br>
<div id="q_0_1_0_x" style="display:none;visibility:hidden"></div>
<input type="radio" name="q_0_1" id="q_0_1_1" value="1"onClick="onclickradio1();"><label for="q_0_1_1"><font color="#3366FF">Light Blue</font></label> <br>
<div id="q_0_1_1_x" style="display:none;visibility:hidden"></div>
<input type="radio" name="q_0_1" id="q_0_1_2" value="2"onClick="onclickradio1();"><label for="q_0_1_2"><font color="#3366FF">Pink</font></label> <br>
<div id="q_0_1_2_x" style="display:none;visibility:hidden"></div>
<input type="radio" name="q_0_1" id="q_0_1_3" value="3"onClick="onclickradio1();"><label for="q_0_1_3"><font color="#3366FF">Brown</font></label> <br>

<div id="q_0_1_3_x" style="display:none;visibility:hidden"></div><br>
<font color="#000000"><b><div>What's the day after tomorrow ?</div></b></font><br>
<input type="radio" name="q_0_2" id="q_0_2_0" value="0"onClick="onclickradio2();"><label for="q_0_2_0"><font color="#3366FF">Monday</font></label> <br>
<div id="q_0_2_0_x" style="display:none;visibility:hidden"></div>
<input type="radio" name="q_0_2" id="q_0_2_1" value="1"onClick="onclickradio2();"><label for="q_0_2_1"><font color="#3366FF">Tuesday</font></label> <br>
<div id="q_0_2_1_x" style="display:none;visibility:hidden"></div>
<input type="radio" name="q_0_2" id="q_0_2_2" value="2"onClick="onclickradio2();"><label for="q_0_2_2"><font color="#3366FF">Friday</font></label> <br>
<div id="q_0_2_2_x" style="display:none;visibility:hidden"></div>
<input type="radio" name="q_0_2" id="q_0_2_3" value="3"onClick="onclickradio2();"><label for="q_0_2_3"><font color="#3366FF">Saturday</font></label> <br>

<div id="q_0_2_3_x" style="display:none;visibility:hidden"></div><br>
<font color="#000000"><b><div>Where does the river come from ?</div></b></font><br>
<input type="radio" name="q_0_3" id="q_0_3_0" value="0"onClick="onclickradio3();"><label for="q_0_3_0"><font color="#3366FF">Mountain</font></label> <br>
<div id="q_0_3_0_x" style="display:none;visibility:hidden"></div>
<input type="radio" name="q_0_3" id="q_0_3_1" value="1"onClick="onclickradio3();"><label for="q_0_3_1"><font color="#3366FF">Lake</font></label> <br>
<div id="q_0_3_1_x" style="display:none;visibility:hidden"></div>
<input type="radio" name="q_0_3" id="q_0_3_2" value="2"onClick="onclickradio3();"><label for="q_0_3_2"><font color="#3366FF">Sea</font></label> <br>
<div id="q_0_3_2_x" style="display:none;visibility:hidden"></div>
<input type="radio" name="q_0_3" id="q_0_3_3" value="3"onClick="onclickradio3();"><label for="q_0_3_3"><font color="#3366FF">All</font></label> <br>
<div id="q_0_3_3_x" style="display:none;visibility:hidden"></div>


- I try to take the value of three ratio by the command document.form.q_0_1.value (exampe for the first ratio, and they are put in the form named 'form'. But i cannot, can anyone tell my why ???

jscheuer1
11-07-2007, 04:35 AM
I don't fully understand the question, but I can tell you that if you want the value of q_0_1, since there are more than one, you would need to do something like so:


for (var e=document.forms['form'].elements, i = e.length-1; i >-1 ; --i)
if(e[i].name=='q_0_1'&&e[i].checked)
alert(e[i].value)

to get it.