...

View Full Version : Survey Form Total Points



mtd
01-21-2006, 05:46 PM
Hi!

I have a survey form like so:

<tr>
<td>Registration Process</td>
<td><input name="B" type="radio" value="0"></td>
<td><input name="B" type="radio" value="1"></td>
<td><input name="B" type="radio" value="2"></td>
<td><input name="B" type="radio" value="3"></td>
<td><input name="B" type="radio" value="4"></td>
<td><input name="B" type="radio" value="5"></td>
</tr>
<tr>
<td>Cost</td>
<td><input name="C" type="radio" value="0"></td>
<td><input name="C" type="radio" value="1"></td>
<td><input name="C" type="radio" value="2"></td>
<td><input name="C" type="radio" value="3"></td>
<td><input name="C" type="radio" value="4"></td>
<td><input name="C" type="radio" value="5"></td>
</tr>
etc... Where a user can rate items from 1-5 (5 being best); the "0" value is a "not applicable" option.

My Question: How can I display a total score at the end (i.e. 26/30 points)? I have seen this done with shopping carts, etc, but I don't need any currency options, just the ability to add/subtract the integer point values.

ALSO, it is important that if a user selects a "n/a (0)" for a category, that the total possible points are lowered to reflect that. For example, if there are 3 categories and the selection is as follows:

1) "n/a" (0)
2) "n/a" (0)
3) "4" (4)

then the score will be 4/5, not 4/15.

Anyone know how to do this with Javascript? I am not very familiar with JS, so any help is appreciated (I'm more of a server-side guy). Cross-browser is good, but not essential.

Thanks!

vwphillips
01-21-2006, 09:52 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--

function Cal(obj){
var total=0;
var ticked=0;
for (var zxc0=1;zxc0<obj['B'].length;zxc0++){
if (obj['B'][zxc0].checked){
total+=obj['B'].length-1;
ticked+=zxc0;
}
}
for (var zxc1=1;zxc1<obj['C'].length;zxc1++){
if (obj['C'][zxc1].checked){
total+=obj['C'].length-1;
ticked+=zxc1;
}
}
for (var zxc2=1;zxc2<obj['D'].length;zxc2++){
if (obj['D'][zxc2].checked){
total+=obj['D'].length-1;
ticked+=zxc2;
}
}
obj['Score'].value='Score: '+ticked+'/'+total;
}
//-->
</script></head>

<body>
<form >
<table onclick="Cal(this.parentNode);" >
<tr>
<td>Registration Process</td>
<td><input name="B" type="radio" ></td>
<td><input name="B" type="radio" ></td>
<td><input name="B" type="radio" ></td>
<td><input name="B" type="radio" ></td>
<td><input name="B" type="radio" ></td>
<td><input name="B" type="radio" ></td>
</tr>
<tr>
<td>Cost</td>
<td><input name="C" type="radio" ></td>
<td><input name="C" type="radio" ></td>
<td><input name="C" type="radio" ></td>
<td><input name="C" type="radio" ></td>
<td><input name="C" type="radio" ></td>
<td><input name="C" type="radio" ></td>
</tr>
<tr>
<td>Cost</td>
<td><input name="D" type="radio" ></td>
<td><input name="D" type="radio" ></td>
<td><input name="D" type="radio" ></td>
<td><input name="D" type="radio" ></td>
<td><input name="D" type="radio" ></td>
<td><input name="D" type="radio" ></td>
</tr>
<tr>
<td colspan="6"><input name="Score" type="text" value="0"></td>
</tr>
</table>
</form>

</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum