Forum Moderators: open

Message Too Old, No Replies

Calculate total and average problem

         

jowan

3:25 pm on Apr 10, 2004 (gmt 0)

10+ Year Member



I have a dynamic generated form fields which allow only number. I intent to calculate the total and average before submitting it to the database. The total is get by multiple the marks value with a credit and put it in totalMarks. The average is calculate after that and put the value on the aveMarks field. The script run no error but return no result in totalMarks and aveMarks fields. Can anyone please kindly help me. Thank you

<form action=abc.asp method=post name=form1>
<%
subjNo=0
Do While NOT sRS.EOF
subjNo=subjNo+1

%>
<td width="150"><%=sRS("subjName")%></td>
<td colspan="4">

<input type="text" name="marks<%=subjNo%>" id="marks<%=subjNo%>" size="4" maxlength="3">

<input type="hidden" name="subjID<%=subjNo%>" value="<%= sRS("subjID")%>">

<input type="hidden" name="credit<%=subjNo%>" value="<%=cRS("subjCrd")%>">
</tr>
<%
sRS.moveNext
Loop
<input type="text" maxlength="3" name="totalMarks" size="6" <%="READONLY"%>>
<input type="button" onclick=calc(form1) name="calculate" value="Hitung">

<td colspan="4"><input type="text" maxlength="3" name="aveMarks" size="6" <%="READONLY"%>>
</form>

<script language="javascript">
<!--

function calc(frm)
{
for (i=0; i < frm.subjNo; i++)
{
if (frm.marks[i].value!= -1)
var totalMarks=totalMarks + (marks[i]*credit[i]);
var totalCredit=totalCredit + credit[i];
var aveMarks=totalMarks/totalCredit;
formarks.totalMarks.value=totalMarks;
formarks.aveMarks.value=aveMarks;

return;

}
}
//-->
</script>

mattglet

2:51 am on Apr 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First thing is:

frm.subjNo

is not a valid field in your form.

-Matt