By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 744 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

post the result back to same page??

P: n/a
<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>
Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <jr*******@hotmail.com> wrote in message
news:#A**************@TK2MSFTNGP12.phx.gbl...
<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>

Jul 19 '05 #2

P: n/a
<%
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
Jul 19 '05 #3

P: n/a
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#**************@TK2MSFTNGP11.phx.gbl...
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" <jr*******@hotmail.com> wrote in message
news:#A**************@TK2MSFTNGP12.phx.gbl...
<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>


Jul 19 '05 #4

P: n/a
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" <jr*******@hotmail.com> wrote in message
news:Om**************@TK2MSFTNGP12.phx.gbl...
: 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#**************@TK2MSFTNGP11.phx.gbl...
: > 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" <jr*******@hotmail.com> wrote in message
: > news:#A**************@TK2MSFTNGP12.phx.gbl...
: > > <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>
: > >
: > >
: >
: >
:
:
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.