Performing Calculations - Noobie Question

S

special_agent69

Not sure if this is a stoopid question or not. If it is, my apologies.

I'd like to have an ASP form performing a relatively simple calculation.

For example, if I wanted to create a simple order form where someone enters
a quantity of tickets, the form would automatically calculate the total cost
in a second text box based on the number (qty) entered times the cost of a
single ticket. Such that, if the user entered "2" in one text box, it would
automatically generate the total cost of, say $34.00 in a second text box
based on the cost of a single ticket being $17.00.

Can someone point me to a tutorial on how to go about doing this?

TIA

SAIC69
 
A

Adrian Forbes [ASP MVP]

You can't do that from ASP so you'd need to use scripting on the client;


<form name="TestForm">
<input type=text name=txtQuantity onKeyUp="ShowTotal()"
onChange="ShowTotal()">
<input type=text name=txtTotal>
</form>

<script language=VBScript>
sub ShowTotal
on error resume next
document.TestForm.txtTotal.value = document.TestForm.txtQuantity.value * 17
on error goto 0
end sub
</script>
 
T

Tom B

FormPage.asp

<form method=post action=PostPage.asp>
<table>
<tr><th>Qty</th><td><input name=Qty></td></tr>
<tr><th>Price</th><td>$17.00</td></tr>
<tr><td colspan=2 align=center><input type=submit
value="calculate"></td></tr>
</table>

PostPage.asp

<%
Dim lngQty
lngQty=Request.Form("Qty")
if isNumeric(lngQty) then
Response.Write "The total is ......" & lngQty * 17.00
end if
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top