Advo wrote:
ive duplicated a simple questionnaire as shown here:
http://www.hackeradio.com/questionnaire.html
meaning there are 8 questions, each with 8 possible answers.
Each row of the answers has its own name ie:
question12_answer1 - question12_answer8
and each of those has a value of 1 - 8
[...]
on form submit i want to run a bit of code(already got this set up) so
that I can validate if only one answer 1 has been selected, one answer 2
and so on.
So 1 can only be used once, 2 can be used only once, all the way to 8.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
function CH(clickedValue, boxName)
{
var usedValues = new Array();
var n = 0;
for(x=0; x<document.forms[0].length; ++ x)
{
var t = document.forms[0]
if (t.elements[x].type=='radio'
&& t.elements[x].name != boxName
&& t.elements[x].checked
)
{
usedValues[n] = t.elements[x].value
++ n
}
}
for(y=0; y < usedValues.length; ++ y)
{
if (clickedValue == usedValues[y])
{
alert('Value was already clicked for another question!')
for (z=0; z < t.elements[boxName].length; ++ z)
{
t.elements[boxName][z].checked = false;
}
}
}
}
</script>
</head>
<body>
<form method="get">
<h3>Question 1</h3>
<input type="radio" name="q1" value="1"
onClick="CH(this.value,this.name)">1
<input type="radio" name="q1" value="2"
onClick="CH(this.value,this.name)">2
<input type="radio" name="q1" value="3"
onClick="CH(this.value,this.name)">3
<input type="radio" name="q1" value="4"
onClick="CH(this.value,this.name)">4
<input type="radio" name="q1" value="5"
onClick="CH(this.value,this.name)">5
<h3>Question 2</h3>
<input type="radio" name="q2" value="1"
onClick="CH(this.value,this.name)">1
<input type="radio" name="q2" value="2"
onClick="CH(this.value,this.name)">2
<input type="radio" name="q2" value="3"
onClick="CH(this.value,this.name)">3
<input type="radio" name="q2" value="4"
onClick="CH(this.value,this.name)">4
<input type="radio" name="q2" value="5"
onClick="CH(this.value,this.name)">5
<h3>Question 3</h3>
<input type="radio" name="q3" value="1"
onClick="CH(this.value,this.name)">1
<input type="radio" name="q3" value="2"
onClick="CH(this.value,this.name)">2
<input type="radio" name="q3" value="3"
onClick="CH(this.value,this.name)">3
<input type="radio" name="q3" value="4"
onClick="CH(this.value,this.name)">4
<input type="radio" name="q3" value="5"
onClick="CH(this.value,this.name)">5
<h3>Question 4</h3>
<input type="radio" name="q4" value="1"
onClick="CH(this.value,this.name)">1
<input type="radio" name="q4" value="2"
onClick="CH(this.value,this.name)">2
<input type="radio" name="q4" value="3"
onClick="CH(this.value,this.name)">3
<input type="radio" name="q4" value="4"
onClick="CH(this.value,this.name)">4
<input type="radio" name="q4" value="5"
onClick="CH(this.value,this.name)">5
<h3>Question 5</h3>
<input type="radio" name="q5" value="1"
onClick="CH(this.value,this.name)">1
<input type="radio" name="q5" value="2"
onClick="CH(this.value,this.name)">2
<input type="radio" name="q5" value="3"
onClick="CH(this.value,this.name)">3
<input type="radio" name="q5" value="4"
onClick="CH(this.value,this.name)">4
<input type="radio" name="q5" value="5"
onClick="CH(this.value,this.name)">5
</form>
</body>
</html>
Hope this helps,
--
Bart