Doing math on form results in Frontpage

Doing math on form results…
This example was given to us by JohnJ at…
This article describes how to add form field values together before sending the results to your database…

There are a few ways to do this. Below is probably the easiest and requires
little custom ASP. It is the two page method.

First create two new pages in FrontPage. Call one “input.asp” and one
“send.asp” (without the quotes).

On input.asp create a form with two text fields. Double-click the first text
field and name it “number” (without the quotes). Double-click the second text
field and name it “cost” (without the quotes).

Right click inside the form and select Form Properties. Put a bullet next to
“Send to Other” and click Options. In the Options, you want to type
“send.asp” (without the quotes) in the Action line and be sure it says Post in
the Method line.

In a nut shell: This page asks for the number of units and the cost per unit
and sends this information to the page called send.asp.

On send.asp we are going to do the math and send this information to the
database. We need to declare three variables and give them values you can copy the
following code and paste it above the initial <html> tag in HTML view in
FrontPage. You do need the quotes this time, and don’t forget the delimiters:
<% and %>:

dim n, c, t
n = request(“number”)
c = request(“cost”)
t = c*n

 what that code does is set the variables and requests them from the form.

Click back to normal view and click Insert | Form | Form. Then delete the
reset button. Place the cursor directly to the left of the submit button and Hit enter.

Place the cursor directly to the left of the submit button and Hit enter. Then
type “Thanks for the information”. You input [now click back to HTML view] and
type <%=n%> [and click back to normal view, note: you will not see any asp
script in normal view] and hit the space bar and type [space bar] for the
quantity, and [click back to HTML view] <%=c%> [and click back to normal] and
type [space bar] for the cost. Then type: “If this is correct, click Submit”

Next right-click inside this form and click on Form Properties and click the
Advanced button. Here we are going to add hidden fields. Click Add and type
Cost for the Name and <%=c%> for the value. Click OK. Click Add and type
Number for the name and <%=n%> for the value, and then add another one named
total and <%=t%> as the value. Then OK back to the Properties. In the
properties we want to Send to Database and click on Options. Here create a
new database and allow FrontPage to create the new database for you. Click on
the Saved Fields and make sure that all three fields are mapped.

Click OK and save these pages.

Now you can publish them to a server and test them out.

Leave a Reply

Your email address will not be published.