...

View Full Version : Calculating a Total from Dynamic Textboxes??



DakotaChick
03-23-2006, 11:05 AM
I'm having issues with trying to calculate the total value of a dynamic number of text boxes. I've tried using:


<%
dim qty, bCart
bCart = Split(Session("CartContents"),"|")
qty = 0
dim ship, subtot, gtot
For i = 0 to UBound(bCart)
%>
qty += cint(document.Order.Quantity(<%'i%>).Value)
<%
Next
ship = 4.99*(fix(qty/2)+1)
'subtot = //dunno how to pull a single peice of info from a huge string, need help here as well...
tgtot = ship+subtot

but I get an error saying type mismatch in refrence to the qty += line...
Knowing the total quantity is dire to calculating shipping. How do I manage to cycle through the textboxes created by this code:


<%
Dim aCart, i, aItems, x, itemcnt
itemcnt = 0
aCart = Split(Session("CartContents"),"|")
For i = 0 to UBound(aCart)
Response.Write "<tr>"
aItems = Split(aCart(i),"-")
For x = 0 to UBound(aItems)
Response.Write "<td>" & aItems(x) & "</td>"
Next
%>
<td><input name="Quantity<%=i%>" type="text" size="8" value="1" /></td>
</tr>
<%
Next
%>
and successfully get a total so that I can calculate shipping?

degsy
03-23-2006, 04:48 PM
Are you using ASP Javascript or ASP VBScript?
Is it Server or Client side?

It's looks as though you are mixing the two.

DakotaChick
03-24-2006, 05:20 PM
I'd like to stick with vbscript since I've had more experience with it.

Adding an item to the cart is server side, but the quantity per item is chosen by the user.

Archangel
03-24-2006, 07:20 PM
From all my dealings ASP doesn't recognize +=

Have you tried changing the += to

qty = qty + cint(document.Order.Quantity(<%'i%>).Value)

Roelf
03-24-2006, 08:23 PM
From all my dealings ASP doesn't recognize +=

Have you tried changing the += to

qty = qty + cint(document.Order.Quantity(<%'i%>).Value)
But the document.Order.Quantity(<%'i%>).Value thing looks to me like client side javascript. :confused:

Archangel
03-24-2006, 09:15 PM
But the document.Order.Quantity(<%'i%>).Value thing looks to me like client side javascript.

You're right...it does, but he's trying to add is using ASP.

I haven't used arrays in ASP enough to know how to grab the dynamic named boxes, but I'm sure there is a way.

I can show you how to do it in PHP :)

DakotaChick
03-25-2006, 07:56 PM
You're right...it does, but he's trying to add is using ASP.She =)



I haven't used arrays in ASP enough to know how to grab the dynamic named boxes, but I'm sure there is a way.

I can show you how to do it in PHP :) I have no clue about php...i'm still getting the hang of asp/vbscript right now and think that would just serve to confuse me more =/ thanks for the offer tho.


But the document.Order.Quantity(<%'i%>).Value thing looks to me like client side javascript. :confused:
Its the only thing i've ever used to refrence form items. If its not vbscript then please tell me what I'm supposed to be using. That peice of code came from a friend who uses vbscript/asp for her job.

miranda
03-26-2006, 05:48 PM
See my answer on the other thread. I take it this is the same question. If not then the same principle applies.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum