post the result back to same page??

Discussion in 'ASP General' started by John Davis, Sep 15, 2003.

  1. John Davis

    John Davis Guest

    <html>
    <body>
    <Form action="calc.asp" method="post" name="calc">
    <P>NUM1: <input type="text" name="num1">
    <P>NUM2: <input type="text" name="num2">
    <P>RESULT: <input type="text" name="result">
    <P><input type="submit">
    </Form>

    I want to write an ASP page to accept 2 numbers, and return the sum on the
    same page. Can we do it in pure ASP without JavaScript?? It sounds an easy
    problem, and I did that in ASP.NET and JavaScript, but failed in pure ASP
    3.0. Here's the attempts, but definitely not what I want because I want the
    result back to the text field.

    <%
    Dim num1, num2, result
    num1 = CInt(Request.Form("num1"))
    num2 = CInt(Request.Form("num2"))
    result = num1 + num2
    Response.Write("<P>Num1 = " & num1)
    Response.Write("<P>Num2 = " & num2)
    Response.Write("<P>Num3 = " & result)
    %>


    </body>
    </html>
     
    John Davis, Sep 15, 2003
    #1
    1. Advertising

  2. John Davis

    Ray at home Guest

    If you want the result to be in the text field for the result, you have to
    write the result into the value of that form element as such.


    <%
    Dim num1, num2, result
    num1 = CInt(Request.Form("num1"))
    num2 = CInt(Request.Form("num2"))
    result = num1 + num2
    %>

    <html>
    <body>
    <Form action="calc.asp" method="post" name="calc">
    <P>NUM1: <input type="text" name="num1" value="<%=num1%>">
    <P>NUM2: <input type="text" name="num2" value="<%=num2%>">
    <P>RESULT: <input type="text" name="result" value="<%=result%>">
    <P><input type="submit">
    </Form>




    </body>
    </html>

    Ray at home




    "John Davis" <> wrote in message
    news:#...
    > <html>
    > <body>
    > <Form action="calc.asp" method="post" name="calc">
    > <P>NUM1: <input type="text" name="num1">
    > <P>NUM2: <input type="text" name="num2">
    > <P>RESULT: <input type="text" name="result">
    > <P><input type="submit">
    > </Form>
    >
    > I want to write an ASP page to accept 2 numbers, and return the sum on the
    > same page. Can we do it in pure ASP without JavaScript?? It sounds an easy
    > problem, and I did that in ASP.NET and JavaScript, but failed in pure ASP
    > 3.0. Here's the attempts, but definitely not what I want because I want

    the
    > result back to the text field.
    >
    > <%
    > Dim num1, num2, result
    > num1 = CInt(Request.Form("num1"))
    > num2 = CInt(Request.Form("num2"))
    > result = num1 + num2
    > Response.Write("<P>Num1 = " & num1)
    > Response.Write("<P>Num2 = " & num2)
    > Response.Write("<P>Num3 = " & result)
    > %>
    >
    >
    > </body>
    > </html>
    >
    >
     
    Ray at home, Sep 15, 2003
    #2
    1. Advertising

  3. John Davis

    dlbjr Guest

    <%
    dblNum1 = Trim(Request("num1"))
    dblNum2 = Trim(Request("num2"))
    If IsNUmeric(dblNum1) And IsNumeric(dblNum2) Then
    Select Case UCase(Trim(Request("CHOICE")))
    Case "ADD"
    dblAnswer = CDbl(dblNum1) + CDbl(dblNum2)
    Case "SUBTRACT"
    dblAnswer = CDbl(dblNum1) - CDbl(dblNum2)
    Case "MULTIPLY"
    dblAnswer = CDbl(dblNum1) * CDbl(dblNum2)
    Case "DIVIDE"
    dblAnswer = CDbl(dblNum1) / CDbl(dblNum2)
    Case Else
    dblAnswer = ""
    End Select
    End If
    %>
    <html>
    <body>
    <form action="addtest.asp" method="post" name="calc" ID="Form1">
    NUM1: <input type="text" name="num1" value="<%=dblNum1%>"><br>
    NUM2: <input type="text" name="num2" value="<%=dblNum2%>"><br>
    RESULT: <input type="text" name="result" value="<%=dblAnswer%>"><br>
    <input type="submit" name="CHOICE" value="Add">
    <input type="submit" name="CHOICE" value="Subtract">
    <input type="submit" name="CHOICE" value="Multiply">
    <input type="submit" name="CHOICE" value="Divide">
    </form>
    </body>
    </html>


    -dlbjr

    invariable unerring alien
     
    dlbjr, Sep 15, 2003
    #3
  4. John Davis

    John Davis Guest

    yeah, that's what I want, except each text field is filled with 0 before the
    user enters any number. Any workarounds on that??

    "Ray at home" <myfirstname at lane 34 . komm> wrote in message
    news:e#...
    > If you want the result to be in the text field for the result, you have to
    > write the result into the value of that form element as such.
    >
    >
    > <%
    > Dim num1, num2, result
    > num1 = CInt(Request.Form("num1"))
    > num2 = CInt(Request.Form("num2"))
    > result = num1 + num2
    > %>
    >
    > <html>
    > <body>
    > <Form action="calc.asp" method="post" name="calc">
    > <P>NUM1: <input type="text" name="num1" value="<%=num1%>">
    > <P>NUM2: <input type="text" name="num2" value="<%=num2%>">
    > <P>RESULT: <input type="text" name="result" value="<%=result%>">
    > <P><input type="submit">
    > </Form>
    >
    >
    >
    >
    > </body>
    > </html>
    >
    > Ray at home
    >
    >
    >
    >
    > "John Davis" <> wrote in message
    > news:#...
    > > <html>
    > > <body>
    > > <Form action="calc.asp" method="post" name="calc">
    > > <P>NUM1: <input type="text" name="num1">
    > > <P>NUM2: <input type="text" name="num2">
    > > <P>RESULT: <input type="text" name="result">
    > > <P><input type="submit">
    > > </Form>
    > >
    > > I want to write an ASP page to accept 2 numbers, and return the sum on

    the
    > > same page. Can we do it in pure ASP without JavaScript?? It sounds an

    easy
    > > problem, and I did that in ASP.NET and JavaScript, but failed in pure

    ASP
    > > 3.0. Here's the attempts, but definitely not what I want because I want

    > the
    > > result back to the text field.
    > >
    > > <%
    > > Dim num1, num2, result
    > > num1 = CInt(Request.Form("num1"))
    > > num2 = CInt(Request.Form("num2"))
    > > result = num1 + num2
    > > Response.Write("<P>Num1 = " & num1)
    > > Response.Write("<P>Num2 = " & num2)
    > > Response.Write("<P>Num3 = " & result)
    > > %>
    > >
    > >
    > > </body>
    > > </html>
    > >
    > >

    >
    >
     
    John Davis, Sep 15, 2003
    #4
  5. John Davis

    Ken Schaefer Guest

    Just detect if the form has been posted or not.

    <%
    If UCase(Request.ServerVariables("Request_Method")) = "POST" then

    intNum1 = Request.Form("txtNumber1")
    intNum2 = Request.Form("txtNumber2")

    intTotal = intNum1 + intNum2

    Else

    intNum1 = 0
    intNum2 = 0

    End If
    %>
    <html>
    <head>
    </head>
    <body>
    <form method="post">
    <input type="text" name="txtNumber1" value="<%=intNum1%>"><br>
    <input type="text" name="txtNumber2" value="<%=intNum2%>"><br>
    <input type="submit">
    </form>

    <p>
    The total is: <%=intTotal%>
    </p>
    </body>
    </html>




    "John Davis" <> wrote in message
    news:...
    : yeah, that's what I want, except each text field is filled with 0 before
    the
    : user enters any number. Any workarounds on that??
    :
    : "Ray at home" <myfirstname at lane 34 . komm> wrote in message
    : news:e#...
    : > If you want the result to be in the text field for the result, you have
    to
    : > write the result into the value of that form element as such.
    : >
    : >
    : > <%
    : > Dim num1, num2, result
    : > num1 = CInt(Request.Form("num1"))
    : > num2 = CInt(Request.Form("num2"))
    : > result = num1 + num2
    : > %>
    : >
    : > <html>
    : > <body>
    : > <Form action="calc.asp" method="post" name="calc">
    : > <P>NUM1: <input type="text" name="num1" value="<%=num1%>">
    : > <P>NUM2: <input type="text" name="num2" value="<%=num2%>">
    : > <P>RESULT: <input type="text" name="result" value="<%=result%>">
    : > <P><input type="submit">
    : > </Form>
    : >
    : >
    : >
    : >
    : > </body>
    : > </html>
    : >
    : > Ray at home
    : >
    : >
    : >
    : >
    : > "John Davis" <> wrote in message
    : > news:#...
    : > > <html>
    : > > <body>
    : > > <Form action="calc.asp" method="post" name="calc">
    : > > <P>NUM1: <input type="text" name="num1">
    : > > <P>NUM2: <input type="text" name="num2">
    : > > <P>RESULT: <input type="text" name="result">
    : > > <P><input type="submit">
    : > > </Form>
    : > >
    : > > I want to write an ASP page to accept 2 numbers, and return the sum on
    : the
    : > > same page. Can we do it in pure ASP without JavaScript?? It sounds an
    : easy
    : > > problem, and I did that in ASP.NET and JavaScript, but failed in pure
    : ASP
    : > > 3.0. Here's the attempts, but definitely not what I want because I
    want
    : > the
    : > > result back to the text field.
    : > >
    : > > <%
    : > > Dim num1, num2, result
    : > > num1 = CInt(Request.Form("num1"))
    : > > num2 = CInt(Request.Form("num2"))
    : > > result = num1 + num2
    : > > Response.Write("<P>Num1 = " & num1)
    : > > Response.Write("<P>Num2 = " & num2)
    : > > Response.Write("<P>Num3 = " & result)
    : > > %>
    : > >
    : > >
    : > > </body>
    : > > </html>
    : > >
    : > >
    : >
    : >
    :
    :
     
    Ken Schaefer, Sep 15, 2003
    #5
    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. =?Utf-8?B?RGF2ZSBCcm93bg==?=

    HttpWebRequest POST result is not the same as POST via ServerXMLHT

    =?Utf-8?B?RGF2ZSBCcm93bg==?=, Nov 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,165
    Joerg Jooss
    Nov 10, 2005
  2. =?Utf-8?B?Z29yaWxsYQ==?=
    Replies:
    1
    Views:
    818
    Masudur
    May 25, 2007
  3. Christopher Brewster
    Replies:
    5
    Views:
    370
    John Machin
    Nov 14, 2008
  4. Michael Tan
    Replies:
    32
    Views:
    1,072
    Ara.T.Howard
    Jul 21, 2005
  5. Samuel Murray
    Replies:
    3
    Views:
    157
    David Mark
    Feb 22, 2010
Loading...

Share This Page