|
Referring to specific form element
Hello all,
I am having trouble. I don't know how to point to a specific element in a form, in an IF statement.
Code:
if(document.forms[0].elements[3].checked==true) {
a = 1
}
else{
a = 0
}
if(document.forms[0].elements[4].checked==true) {
b = 1
}
else{
b = 0
}
The form:
Code:
<form method="get" onsubmit="tester()">
1. Why did the chicken cross the road?
<p>
<input type="radio" name="R1" value="val7">
a. Jacques Derrida: Any number of contending discourses may be discovered within the act of the chicken crossing the road, and each interpretation is equally valid as the authorial intent can never be discerned, because structuralism is DEAD, DAMMIT, DEAD!
</p>
<p>
<input type="radio" name="R1" value="val8">
b. Salvador Dali: The Fish.
</p>
<p>
<input type="radio" name="R1" value="val9">
c. Both A & B. </p>
2. How many Accountants does it take to change a light bulb?
<p>
<input type="radio" name="R2" value="val4">
a. Both B & C.</p>
<p>
<input type="radio" name="R2" value="val5">
b. None-just assume it's changed.</p>
<p>
<input type="radio" name="R2" value="val6">
c. What sort of answer did you have in mind?</p>
<input type="submit" value="Submit">
</form>
Now for some reason the element[number] does not alway correspond the the actual placement in the form. What I want to do is to uniquely specific the element so there is no chance of error. Hopefully I have explained myself sufficiently.
Any ideas?
Thank you.
|