Velocity Reviews > Performing Calculations - Noobie Question

# Performing Calculations - Noobie Question

special_agent69
Guest
Posts: n/a

 12-18-2003
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

Guest
Posts: n/a

 12-18-2003
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" <(E-Mail Removed)> wrote in message
news:usS9%(E-Mail Removed)...
> 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
>
>

special_agent69
Guest
Posts: n/a

 12-18-2003
I was afraid of that.

SAIC69

"Adrian Forbes [ASP MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:usS9%(E-Mail Removed)...
> > 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
> >
> >

>
>

Tom B
Guest
Posts: n/a

 12-18-2003
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" <(E-Mail Removed)> wrote in message
news:usS9%(E-Mail Removed)...
> 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
>
>