469,929 Members | 1,789 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

Performing Calculations - Noobie Question

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
Jul 19 '05 #1
3 3962
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>

"special_agent69" <SA****@thess.com> wrote in message
news:us****************@TK2MSFTNGP12.phx.gbl...
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

Jul 19 '05 #2
I was afraid of that.

Many thanks for your help

SAIC69

"Adrian Forbes [ASP MVP]" <so***@noemail.zzz> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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>

"special_agent69" <SA****@thess.com> wrote in message
news:us****************@TK2MSFTNGP12.phx.gbl...
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


Jul 19 '05 #3
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
%>

"special_agent69" <SA****@thess.com> wrote in message
news:us****************@TK2MSFTNGP12.phx.gbl...
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

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Aristotelis E. Charalampakis | last post: by
2 posts views Thread by Jeronimo Bertran | last post: by
2 posts views Thread by Zorpiedoman | last post: by
2 posts views Thread by Mike P | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.