Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a number across issue

Status
Not open for further replies.

ro6er

Programmer
Jul 1, 2003
76
It's probably something simple but for some reason the quanity isn't being added from this page:

to :


index.asp has the following code:

<input type="text" name="qty" value="1" size="1">
<input type="hidden" name="dir" value="<%=rsBuckles("price")%>">
<input type="image" src="images/add_basket.gif" border=0 alt="Buy">

cart.asp has this:

<%
session.lcid=2057
Session.Timeout=50


if not isObject(Session("cart")) then
set Session("cart")=Server.CreateObject("Scripting.Dictionary")
end if

add=Request("add")
qty=Request("qty")
del=Request("del")
price=Request("dir")

if add<>"" then
'check if data is no there
if not Session("cart").Exists(add) then 'add to cart
'get data from database this example is without
set recData=Server.CreateObject("Scripting.Dictionary")
recData.Add "cart_no",add
recData.Add "qty",1
recData.Add "price",price
'store the cart to it's cart_no
Session("cart").Add add,recData
else 'flight_id exists
'add only the qty
Session("cart")(add)("qty")=Session("cart")(add)("qty")+CInt(qty)
end if
end if
if del<>"" then
'remove from cart
Session("cart").Remove(del)
end if
'store back to session object


'here display your cart
if IsObject(Session("cart")) then

if Session("cart").Count>0 then
cartItems=Session("cart").Items
For i=Lbound(cartItems) to Ubound(cartItems)
cart_no=cartItems(i)("cart_no")
price=cartItems(i)("price")
qty=cartItems(i)("qty")

'calculate total
orderTotal = orderTotal + cartItems(i)("price") * cartItems(i)("qty")

Response.Write "<td><a href=""cart.asp?del="&cart_no&"""><img src=""images/delete.gif"" border=0></a></td>"
Response.Write "<td>"&(i+1)& ": "&cart_no&" </td><td><b>£"&price&" </b></td><br /></tr>"
Response.Write "<td></td><td>Quanity: "&qty&"</td></tr>"
Next
Response.Write "<td><br /><br /></td><td><b>Total</b></td><td><b>"

'print total
Response.Write formatCurrency( orderTotal )
Response.Write "</b></td>"
Response.Write "</table><div align=""center""><br /><br /><a href=""login.asp""><img src=""images/checkout.gif"" border=0></a></div>"
else
Response.Write ("<td><br /><br /></td><td><b>Your shopping cart is empty</td><td><b>")
end if
end if
%>





Thanks for any help, Roger
 
are you using POST or GET?

have you response.write these values to the screen to see if they are coming accross?

add=Request("add")
qty=Request("qty")
Response.Write qty
del=Request("del")
price=Request("dir")

Try using the
Code:
tags instead of red or other font colors. it's very hard to read your code that way


General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
Hi, sorry about the red ASP.

I used post in the first form I should have included that..

I just tried
Code:
<%Response.Write""&qty&""%>
at the base of cart.asp and after entering 10 on the index.asp it still brought back 1.

Hmm.
 
That is what you are telling it to pass though

Code:
<input type="text" name="qty" [b]value="1"[/b] size="1">

I think you may want no value in there sense you are allowing a dynamic entry


General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
Ah but no. I tried that before the value just acts as a holder so users have a number to start with. I think its something to do with the session that takes place on the cart.asp but i'm not sure what

I did a small test to make sure the method I was using to send a number between pages actually worked. I made one page:
test.asp
Code:
<form method="post" name="form1" action="test2.asp">
<input type="text" name="qty" value="1" size="1">
<input name="submit" type="submit">
</form>
and another page called test2.asp

Code:
<%qty=Request("qty")%>
<%Response.Write""&qty&""%>

And all seems to work fine.
 
><input name="submit" type="submit">
It would be adviseable to not to name it "submit" in most cases.
[tt]<input name="[blue]other_than_submit[/blue]" type="submit">[/tt]
 
Well I actually used
Code:
<input type="image" src="images/add_basket.gif" border=0 alt="Buy">
for the submit that last bit of code was just a test to see if it worked ok on its own without the rest of the code from cart.asp
 
Doh figured it out all I had to do was change
Code:
recData.Add "qty",1
to
Code:
recData.Add "qty"
as that was adding a 1 in place of the number sent from the previous page.

Thanks any way
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top