Click to See Complete Forum and Search --> : Assign Dynamic value to javascript variable


Prit
08-28-2003, 10:56 AM
Hi Everyone,
This is my first post to the froum so please overlook any mistakes in my posting.
My Problem: I have an ASP page which has a repeat region. So the number of rows can vary depending on the account being viewed.
There is a javascript function which calculates the running total. This uses the total number of rows. (thanks to Stephen Travis of Thingumajig). Is there a way where I can allot the total number of rows to this variable?
Any help would be nice
thanks in advance
Prit

Here is part of the code:
<script language="JavaScript"><!--
function Total() {
var q, iCount, Grandtotal, total;
iCount = 1;
Grandtotal = 0;
nitems = 2
//This would be the variable something like nitems=<%=count %>
for (iCount=1; iCount<nitems+1; iCount++) {
eval("q = document.orderform.Item" + iCount + "Invelect.value;");
if (q) {
eval("total=parseInt(q);");
eval("Grandtotal = Grandtotal + total;");
}
}
document.orderform.GrandTotal.value = (Grandtotal);
}
//-->
</script>

Prit
08-28-2003, 03:36 PM
i got away by going around it
I assigned the asp value to a hidden field and then assigned the same value to the javascript variable.
the final code looks like this
function Total() {
var q, iCount, Grandtotal, total;
iCount = 1;
Grandtotal = 0;
eval("nitems = parseInt(document.orderform.Count.value);");

for (iCount=1; iCount<nitems+1; iCount++) {
eval("q = document.orderform.Item" + iCount + "Invelect.value;");
if (q) {
eval("total=parseInt(q);");
eval("Grandtotal = Grandtotal + total;");
}
}
document.orderform.GrandTotal.value = (Grandtotal);
}

with the hidden feild as
<input type="hidden" name=Count value="<%=iCount - 1 %>">

thanks for reading and for the earlier posts ...
I have learnt a lot from going through them
Prit