Performing Calculations - Noobie Question

Discussion in 'ASP General' started by special_agent69, Dec 18, 2003.

  1. 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, Dec 18, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:usS9%...
    > 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
    >
    >
    Adrian Forbes [ASP MVP], Dec 18, 2003
    #2
    1. Advertising

  3. I was afraid of that.

    Many thanks for your help

    SAIC69

    "Adrian Forbes [ASP MVP]" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:usS9%...
    > > 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, Dec 18, 2003
    #3
  4. special_agent69

    Tom B Guest

    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" <> wrote in message
    news:usS9%...
    > 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, Dec 18, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lallous

    Noobie question about Switch

    lallous, Dec 26, 2003, in forum: C++
    Replies:
    6
    Views:
    326
    Chris Mantoulidis
    Dec 27, 2003
  2. Replies:
    0
    Views:
    328
  3. Shaun
    Replies:
    2
    Views:
    552
    Simon Brunning
    Apr 22, 2005
  4. ProvoWallis

    noobie mkdir problem/question

    ProvoWallis, Mar 25, 2006, in forum: Python
    Replies:
    5
    Views:
    315
    Dennis Lee Bieber
    Mar 26, 2006
  5. Bit Byte
    Replies:
    1
    Views:
    819
    Teemu Keiski
    Jan 28, 2007
Loading...

Share This Page