Help,
I have a web based form containg values typed in by the user. The first value is called noItems, which is outside the form. The form contains a persons name, the number of items,noSub, thay have submitted and their final grade. I need to use noItems and noSub to calulate their prcentage and store it in the grade column of the table. How do I use a command button to, when clicked, go through the data on the table and calculate the final grade(as a percentage for each row? When it is run all the fields just go blank.
my code is below:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/conn_3_coast.asp" -->
<%
Dim rs_homework
Dim rs_homework_cmd
Dim rs_homework_numRows
Set rs_homework_cmd = Server.CreateObject ("ADODB.Command")
rs_homework_cmd.ActiveConnection = MM_conn_3_coast_STRING
rs_homework_cmd.CommandText = "SELECT DISTINCT tblStudent.Name, studentResults.enrolno FROM tblStudent INNER JOIN studentResults ON tblStudent.enrolno = studentResults.enrolno ORDER BY tblStudent.Name"
rs_homework_cmd.Prepared = true
Set rs_homework = rs_homework_cmd.Execute
rs_homework_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = 25
Repeat1__index = 0
rs_homework_numRows = rs_homework_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function calcGrade(){
var tbl=document.getElementById('tblgrades');
var tbl1=document.getElementById('tblNhwks_per');
var trs1=tbl1.getElementByTagName('tr');
var trs=tbl.getElementByTagName('tr');
var tds1=tr[1].getElementsByTagName('td');
var noHomeworks = tds1.noHomeworks;
for (var i=0;i<trs.length;i++)
{
//get all the tds in this tr
var tds=tr[i].getElementsByTagName('td');
for (var j=0;j<tds.length;j++)
{
var pcag=(tds.submitted/noHomeworks)/100;
if pcage<50
tds.Grade=3;
if ((pcage>=50) and (pcage<=84))
tds.Grade=2;
if pcage<84
tds.Grade=1;
}
}
function MM_callJS(jsStr) { //v2.0
return eval(jsStr)
}
//-->
</script>
</head>
<body>
<h1>Coast@JCC</h1>
<h1>Homework</h1>
<form id="form2" name="form2" method="post" action="">
<table width="293" border="1" id="tblNhwks_per">
<tr>
<td width="175">Number of Homeworks this period</td>
<td width="102"><input type="text" name="noHomeworks" id="noHomeworks" /></td>
</tr>
</table>
</form>
<p> </p>
<form id="form1" name="form1" method="post" action="">
<table width="596" border="1" id="tblgrades">
<tr>
<td width="201">Name</td>
<td width="107">Enrolment Number</td>
<td width="131">Homeworks Submited</td>
<td width="129">Grade</td>
</tr>
<tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT rs_homework.EOF))
%>
<td><%=(rs_homework.Fields.Item("Name").Value)%> </td>
<td><%=(rs_homework.Fields.Item("enrolno").Value)%> </td>
<td><input type="text" name="submitted" id="submitted" /></td>
<td><input type="text" name="hwkGrade" id="hwkGrade" /></td><tr></tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rs_homework.MoveNext()
Wend
%>
<td height="110"></tr>
</table>
</form>
<form id="form3" name="form3" method="post" action="">
<input name="Calculate" type="submit" id="Calculate" onclick="MM_callJS('calcGrade()')" value="Submit" />
</form>
<form id="form4" name="form4" method="post" action="">
</form>
<p> </p>
<p> </p>
<p>Page title goes here</p>
<p> </p>
<p>Page title goes here</p>
<p> </p>
<p> </p>
</body>
</html>
<%
rs_homework.Close()
Set rs_homework = Nothing
%>