Mon Jun 21, 2010 7:25 am
I need help. I have a form that gives a running total, however, the calculation isn't coming up properly. Any help would be appreciated. I am new to this forum, so if I haven't posted correctly, please let me know.
I attached a notepad file to this post, so if it can't be read, I can post it in here.
Thanks.
***********************<Header>*****************************
<script language="javascript">
function calc()
{
var form = document.forms.Calculator;
var q1 = Number( getSelectedValue(form.elements.q1) );
var q2 = Number( getSelectedValue(form.elements.q2) );
var q3 = Number( getSelectedValue(form.elements.q3) );
var q4 = Number( getSelectedValue(form.elements.q4) );
var q5 = Number( getSelectedValue(form.elements.q5) );
var q6 = Number( getSelectedValue(form.elements.q6) );
var q7 = Number( getSelectedValue(form.elements.q7) );
var q8 = Number( getSelectedValue(form.elements.q8) );
if ( isNaN(q1) || isNaN(q2) || isNaN(q3) || isNaN(q4) || isNaN(q5) || isNaN(q6) || isNaN(q7) || isNaN(q8) ) {
} else {
form.elements.Total.value = q1 + q2 + q3 + q4 + q5 + q6 + q7 + q8;
}
}
function getSelectedValue(flds) {
var i = 0;
var len = flds.length;
while (i < len) {
if (flds[i].checked) {
return flds[i].value;
}
i++;
}
return "";
}
</script>
***********************<form>*****************************
<form name="Calculator" method="post" action="">
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-weight: bold; font-size: 0.8em; font-family: Tahoma, Geneva, sans-serif;">
<tr>
<td> </td>
<td colspan="5" style="font-size: 0.8em; font-weight: bold; text-align: center;">Situations</td>
<td colspan="2" style="text-align: center; font-size: 0.8em; font-weight: bold;">3= High Chance <--> 0=Never Doze</td>
</tr>
<tr>
<td width="5%" style="font-weight: bold">1.</td>
<td colspan="5" style="font-weight: bold">Sitting and Reading</td>
<td colspan="2" style="text-align: center"><label>
<input type="radio" onclick="calc()" name="q1" id="q1" value="3">
3
<input type="radio" onclick="calc()" name="q1" id="q2" value="2">
2
<input type="radio" onclick="calc()" name="q1" id="q3" value="1">
1
<input type="radio" onclick="calc()" name="q1" id="q4" value="0">
0
</label></td>
</tr>
<tr>
<td style="font-weight: bold">2.</td>
<td colspan="5" style="font-weight: bold">Watching TV</td>
<td colspan="2" style="text-align: center"><label>
<input type="radio" onclick="calc()" name="q2" id="q1" value="3">
3
<input type="radio" onclick="calc()" name="q2" id="q2" value="2">
2
<input type="radio" onclick="calc()" name="q2" id="q3" value="1">
1
<input type="radio" onclick="calc()" name="q2" id="q4" value="0">
0 </label></td>
</tr>
<tr>
<td style="font-weight: bold">3.</td>
<td colspan="5" style="font-weight: bold">Sitting, inactive in a public place (e.g. theater, meetings)</td>
<td colspan="2" style="text-align: center"><label>
<input type="radio" onclick="calc()" name="q3" id="q1" value="3">
3
<input type="radio" onclick="calc()" name="q3" id="q2" value="2">
2
<input type="radio" onclick="calc()" name="q3" id="q3" value="1">
1
<input type="radio" onclick="calc()" name="q3" id="q4" value="0">
0 </label></td>
</tr>
<tr>
<td style="font-weight: bold">4.</td>
<td colspan="5" style="font-weight: bold">As a passenger in a car for an hour without a break</td>
<td colspan="2" style="text-align: center"><label>
<input type="radio" onclick="calc()" name="q4" id="q1" value="3">
3
<input type="radio" onclick="calc()" name="q4" id="q2" value="2">
2
<input type="radio" onclick="calc()" name="q4" id="q3" value="1">
1
<input type="radio" onclick="calc()" name="q4" id="q4" value="0">
0 </label></td>
</tr>
<tr>
<td style="font-weight: bold">5.</td>
<td colspan="5" style="font-weight: bold">Lying down to rest in the afternoon when circumstances permit.</td>
<td colspan="2" style="text-align: center"><label>
<input type="radio" onclick="calc()" name="q5" id="q1" value="3">
3
<input type="radio" onclick="calc()" name="q5" id="q2" value="2">
2
<input type="radio" onclick="calc()" name="q5" id="q3" value="1">
1
<input type="radio" onclick="calc()" name="q5" id="q4" value="0">
0 </label></td>
</tr>
<tr>
<td style="font-weight: bold">6.</td>
<td colspan="5" style="font-weight: bold">Sitting and talking to someone</td>
<td colspan="2" style="text-align: center"><label>
<input type="radio" onclick="calc()" name="q6" id="q1" value="3">
3
<input type="radio" onclick="calc()" name="q6" id="q2" value="2">
2
<input type="radio" onclick="calc()" name="q6" id="q3" value="1">
1
<input type="radio" onclick="calc()" name="q6" id="q4" value="0">
0 </label></td>
</tr>
<tr>
<td style="font-weight: bold">7.</td>
<td colspan="5" style="font-weight: bold">Sitting quietly after lunch without alcohol.</td>
<td colspan="2" style="text-align: center"><label>
<input type="radio" onclick="calc()" name="q7" id="q1" value="3">
3
<input type="radio" onclick="calc()" name="q7" id="q2" value="2">
2
<input type="radio" onclick="calc()" name="q7" id="q3" value="1">
1
<input type="radio" onclick="calc()" name="q7" id="q4" value="0">
0 </label></td>
</tr>
<tr>
<td style="font-weight: bold">8. </td>
<td colspan="5" style="font-weight: bold">In a car, while stopped for a few minutes in traffice</td>
<td colspan="2" class="CenteredText" style="text-align: center"><label>
<input type="radio" onclick="calc()" name="q8" id="q1" value="3">
3
<input type="radio" onclick="calc()" name="q8" id="q2" value="2">
2
<input type="radio" onclick="calc()" name="q8" id="q3" value="1">
1
<input type="radio" onclick="calc()" name="q8" id="q4" value="0">
0 </label></td>
</tr>
<tr>
<td> </td>
<td width="10%"> </td>
<td width="10%"> </td>
<td width="10%"> </td>
<td width="10%"> </td>
<td width="13%"> </td>
<td width="36%" class="CenteredText" style="text-align: center"><label>Total</label>
Score**
<input type="text" name="Total" onChange="calc()" readonly size="10">
<br>
<br />
<input type="reset" value="Clear"></td>
<td width="6%"> </td>
</tr>
<tr>
<td colspan="8">**A Score of 9 or Higher may warrant further testing.</td>
</tr>
</table>
</form>
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.