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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP Calculations help

Status
Not open for further replies.

benrob82

Programmer
Jul 28, 2005
116
0
0
GB
Hi,

I'm having the simplest of problems we've implemented worldpay and as you might know worldpay doesn't allow you to enter more than one item at a time.

I want to allow the user to enter say quantity 2 and then calculate the value say 15.00 and then add the result into the worldpay code.

I've been trying and I know its simple but cant get my head round it.

Please someone help. This is what I have so far.

Page1

<!-- #include file="includes/boxtop.inc" --><H1>Online Payment<br>
</H1>
<P>Make you online payment below safely using WorldPay.
</P>
<form action="payment1.asp" method="post">
<p>
<script language='javascript'>
function calcNewTotal() {
Amount = 15.00 * parseInt(document.getElementById('Qty').value);
Total = Total + Amount
document.getElementById('Total').value = Total;
}
</script>
<input type="hidden" name="Total" value="">
<input name="Quantity" type="text" id="Qty" value="<%=Quantity%>" onChange="calcNewTotal();">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<p><br>
</p>
<DIV align=left>*</DIV>
<DIV align=left>*
</DIV>
<!-- #include file="includes/boxbottom.inc" -->



Page2

<!-- #include file="includes/boxtop.inc" --><H1>Online Payment<br>
<%dim Total
Total=request.Form("Total")
%>
</H1>
<P>Make you online payment below safely using WorldPay.
</P>
<form action=" method=POST>
<p>
<input type=hidden name="instId" value="">
<input type=hidden name="cartId" value="1">
<input type=hidden name="amount" value="<%=Total%>">
<input type=hidden name="currency" value="GBP">
<input type=hidden name="desc" value="Event Payment">
<input type=hidden name="testMode" value="">
<input type=submit value="Make Payment">
<br>
</p>
</form><br>
<DIV align=left>*</DIV>
<DIV align=left>*
</DIV>
<!-- #include file="includes/boxbottom.inc" -->


Thanks for the help
 
do you get any error...whats actually happening when you run the code...

-DNG
 
Hi,

No there is no error, it just doesn't seem to be passing the total across to the 2nd page then progressing from the second page to the worldpay page it brings up an error that states invaild amount or currency. Which to me means that the amount is not being passed over. Any ideas?
 
On the form on page1 you've named the hidden field "total" but not given it an ID. Unless it's a typo that's probably your problem.

--------------------------------
Rome did not create a great empire by having meetings, they did it by killing all those who opposed them.
 
no still a problem, what would you suggest that would give me the ability to enter a quantity and then multiply that with a pre defind price and then feed this to the worldpay script?
 
Total = Amount;

--------------------------------
Rome did not create a great empire by having meetings, they did it by killing all those who opposed them.
 
i think he meant to say...

replace this

Total = Total + Amount

with

Total = Amount;

dont miss the semi colon in the end :)

-DNG
 
Sorry, been a long day

In the calcNewTotal() function replace

Total = Total + Amount

with

Total = Amount;

--------------------------------
Rome did not create a great empire by having meetings, they did it by killing all those who opposed them.
 
guys thank you so much, that has been bugging me all day. Your stars
 
any ideas why it won't pass the value when I hit enter and only when I hit submit?
 
My guess is that the onChange event is only fired when "Qty" looses focus. Clicking the submit button changes focus on the form but pressing the enter key does not.

A way round this might be

1) Change the type="submit" to type="button"
2) Give your form a name ie name=QuantityForm
3) Add to your button an onClick event, in this case onClick="document.QuantityForm.submit()"

This would the fire the onChange event but it does mean pressing the enter key would do nothing. There's probably other, if not better, ways but this one works for me.

Hope this helps.

--------------------------------
Rome did not create a great empire by having meetings, they did it by killing all those who opposed them.
 
you can try this code...

Code:
function catchEnter(e) {
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;

if (code==13) {
//submit the form, do your validation, or whatever
}
}

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top