Total members 11895 |It is currently Thu Dec 26, 2024 7:58 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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>&nbsp;</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 &lt;--&gt; 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>&nbsp;</td>
<td width="10%">&nbsp;</td>
<td width="10%">&nbsp;</td>
<td width="10%">&nbsp;</td>
<td width="10%">&nbsp;</td>
<td width="13%">&nbsp;</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%">&nbsp;</td>
</tr>
<tr>
<td colspan="8">**A Score of 9 or Higher may warrant further testing.</td>
</tr>
</table>
</form>




Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Javascript Form Calculation Error :banghead:
 cotact us html and javascript form     -  
 getting gst, pst total to diplay in my javascript form     -  
 I'm having a problem creating a Javascript form. Whats wrong     -  
 php login form (sign-in form)     -  
 ERROR     -  
 skymiles error     -  
 Deliberate Error     -  
 error in code     -  
 Check DNS error     -  
 Java error     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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