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
Necta
<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.value != -1)
var totalMarks=totalMarks + (marks*credit);
var totalCredit=totalCredit + credit;
var aveMarks=totalMarks/totalCredit;
formarks.totalMarks.value=totalMarks;
formarks.aveMarks.value=aveMarks;
return;
}
}
//-->
</script>
Necta
<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.value != -1)
var totalMarks=totalMarks + (marks*credit);
var totalCredit=totalCredit + credit;
var aveMarks=totalMarks/totalCredit;
formarks.totalMarks.value=totalMarks;
formarks.aveMarks.value=aveMarks;
return;
}
}
//-->
</script>