Forums
This topic is locked
Calculate repeating fields
Posted 01 Sep 2004 23:52:04
1
has voted
01 Sep 2004 23:52:04 Bradley Blodgett posted:
Hi all,I have been looking at this issue for a day now, and I'm almost ready to give up. I have a page that is displaying multiple database records using a repeating region, but I also need to add the values to gether. I have been using a modified Yaromat's calculate behavior added to the body rather that on submit. The problem is the repeating region uses the same name for each instance of the text field that I am trying to calculate. Unfortunately, I'm not even close to being a Javascript expert, so this is causing a huge problem for me. Here's what the code looks like:
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/asset.asp" -->
<%
var getibmdata__MMColParam = "1";
if (String(Request.QueryString("systemtype"

String(Request.QueryString("systemtype"


getibmdata__MMColParam = String(Request.QueryString("systemtype"

}
%>
<%
var getibmdata = Server.CreateObject("ADODB.Recordset"

getibmdata.ActiveConnection = MM_asset_STRING;
getibmdata.Source = "SELECT * FROM dbo.IBM_System WHERE Model = '"+ getibmdata__MMColParam.replace(/'/g, "''"

getibmdata.CursorType = 0;
getibmdata.CursorLocation = 2;
getibmdata.LockType = 1;
getibmdata.Open();
var getibmdata_numRows = 0;
%>
<%
var getperiphdata__MMColParam = "0";
if (String(Request.QueryString("s50monitortype1"

String(Request.QueryString("s50monitortype1"


getperiphdata__MMColParam = String(Request.QueryString("s50monitortype1"

}
%>
<%
var getperiphdata__MMColParam1 = "0";
if (String(Request.QueryString("s50monitortype2"

String(Request.QueryString("s50monitortype2"


getperiphdata__MMColParam1 = String(Request.QueryString("s50monitortype2"

}
%>
<%
var getperiphdata__MMColParam2 = "0";
if (String(Request.QueryString("s50monitortype3"

String(Request.QueryString("s50monitortype3"


getperiphdata__MMColParam2 = String(Request.QueryString("s50monitortype3"

}
%>
<%
var getperiphdata = Server.CreateObject("ADODB.Recordset"

getperiphdata.ActiveConnection = MM_asset_STRING;
getperiphdata.Source = "SELECT * FROM dbo.IBM_Periph WHERE IBM_Periph_key = '"+ getperiphdata__MMColParam.replace(/'/g, "''"



getperiphdata.CursorType = 0;
getperiphdata.CursorLocation = 2;
getperiphdata.LockType = 1;
getperiphdata.Open();
var getperiphdata_numRows = 0;
%>
<%
var Repeat1__numRows = -1;
var Repeat1__index = 0;
getperiphdata_numRows += Repeat1__numRows;
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function YY_CalculateForm() { //v3.01
//copyright (c)1999-2000 Yaromat.com
var args=YY_CalculateForm.arguments;
var myResult=""; var myField="0";
if (document.all){eval("args[0]=args[0].replace(/.layers/gi, '.all');"

for (var i=3; i<args.length; i++){
if(args[i].charAt(0)!="#"

myResult=myResult+args[i];
}else{
myField=eval(args[0]+'.'+ args[i].substring(1)+'.value'); if(myField==""

myResult=myResult+myField;
}
}
with (Math) {
var myExpo = pow(10, args[2]);
var myStr = round(myExpo*eval(myResult))/myExpo;
}
eval(args[0]+'.'+args[1]+'.value='+myStr);
}
//-->
</script>
</head>
<body onLoad="YY_CalculateForm('document.form1','textfield3','2','#textfield','+','#textfield2')">
<form action="" name="form1"">
<p> </p>
<table width="100%" border="0" cellpadding="15">
<tr>
<td><strong><%=(getibmdata.Fields.Item("pc_title"

<td> </td>
</tr>
<tr>
<td><input name="textfield" type="text" value="<%=(getibmdata.Fields.Item("IBM_System_Lease_Cost"

<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input name="textfield3" type="text" readonly="true"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<table width="100%" border="0" cellpadding="15">
<% while ((Repeat1__numRows-- != 0) && (!getperiphdata.EOF)) { %>
<tr>
<td><%=(getperiphdata.Fields.Item("Periph_Name"

<td> </td>
</tr>
<tr>
<td><input name="textfield2" type="text" value="<%=(getperiphdata.Fields.Item("IBM_Periph_Lease_Cost"

<td> </td>
</tr>
<%
Repeat1__index++;
getperiphdata.MoveNext();
}
%>
</table>
<p> </p>
<p> </p>
<p>
<input type="reset" name="Reset" value="Reset">
</p>
<p> </p>
<p> </p>
</form>
</body>
</html>
<%
getibmdata.Close();
%>
<%
getperiphdata.Close();
%>
When I look at the source though IE I can clearly see that the repeating region uses the same field name each time. Any help suggestions would be greatly appreciated.
Thanks,
Subg
Replies
Replied 16 Sep 2004 21:54:10
16 Sep 2004 21:54:10 Kent Steelman replied:
May i suggest you use two record sets on your page, Record set one shows the records that will be summed and record set two calculates the sum of the fields displayed. Set it up the same way for record set one as a repeat region, but below the repeat region in a table place the sum value in record set two.
Kent
Wm. Kent Steelman
Kent
Wm. Kent Steelman
Replied 17 Sep 2004 13:46:14
17 Sep 2004 13:46:14 Lee Diggins replied:
Hi SubG
I'm assuming you want to sum these values getperiphdata.Fields.Item("IBM_Periph_Lease_Cost"
.Value? A way to this this would be to dim a variable just before your repeat region:
Dim numOut
while ((Repeat1__numRows-- != 0) && (!getperiphdata.EOF))
numOut = numOut + getperiphdata.Fields.Item("IBM_Periph_Lease_Cost"
.Value
Then somewhere further down the page outside your repeat region, do a response.write(numOut)
Digga
Sharing Knowledge Saves Valuable Time!!!
Edited by - Digga the Wolf on 17 Sep 2004 13:47:21
I'm assuming you want to sum these values getperiphdata.Fields.Item("IBM_Periph_Lease_Cost"

Dim numOut
while ((Repeat1__numRows-- != 0) && (!getperiphdata.EOF))
numOut = numOut + getperiphdata.Fields.Item("IBM_Periph_Lease_Cost"

Then somewhere further down the page outside your repeat region, do a response.write(numOut)
Digga
Sharing Knowledge Saves Valuable Time!!!
Edited by - Digga the Wolf on 17 Sep 2004 13:47:21