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?
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(){


}
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">
    <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>&nbsp;</p>
<form id="form1" name="form1" method="post" action="">
  <table width="596" border="1">
    <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" value="0"/></td>
        <td><input type="text" name="hwkGrade" id="hwkGrade" value="0" /></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>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Page title goes here</p>
<p>&nbsp;</p>
<p>Page title goes here</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
<%
rs_homework.Close()
Set rs_homework = Nothing
%>

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?
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(){


}
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">
<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>&nbsp;</p>
<form id="form1" name="form1" method="post" action="">
<table width="596" border="1">
<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" value="0"/></td>
<td><input type="text" name="hwkGrade" id="hwkGrade" value="0" /></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>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Page title goes here</p>
<p>&nbsp;</p>
<p>Page title goes here</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
<%
rs_homework.Close()
Set rs_homework = Nothing
%>

You'll need to look into the Javascript DOM. You'll need to select all the <tr> elements in your table and then go through the <td> elements in each <tr> element, calculating the sum of the <td> nodeValue's. (whats inside the <td> element).

first give your <table> and id so it's easier to select. eg: id="mytable".

var tbl = document.getElementById('mytable');

select all the <tr> elements.

var trs = tbl.getElementsByTagName('tr');

iterate through each tr.

for (var i = 0; i < trs.length; i++)
{

// get all the tds in this tr
var tds = tr[i].getElementsByTagName('td');
var sum = 0;
for (var j = 0; j < tds.length; j++) {
sum += tds.nodeValue; // change to appropriate code
}

}

hope that starts you off in the right direction.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.