How to complete mathematical calculations on a form before you send data to a database in FrontPage 2003 (823520)
The information in this article applies to:
- Microsoft Office FrontPage 2003
For a Microsoft Front Page 2002 version of this
article, see
319308. SUMMARY In a Microsoft Office FrontPage 2003 Web, you may want to
calculate data in a Web page and then send that data to a database. For
example, you may want to automatically calculate a total based on values that
are entered by the user, and then send that total value to a database.
There are a number of ways to perform this type of calculation. One
of the easiest ways is to use simple Active Server Pages (ASP) pages.
To create ASP pages that calculate and submit a total to a database,
use the following methods, in the order that they are presented. Create the ASP pages in FrontPage- Start FrontPage.
- On the File menu, click
New.
- On the File menu, click
Save.
- In the Save As dialog box, type
input.asp, and then click Save.
- On the File menu, click
New, and then click Blank Page.
- On the File menu, click
Save.
- In the Save As dialog box, type
send.asp, and then click Save.
Modify the Input.asp page The purpose of the Input.asp page is to gather the values to be
calculated by providing input boxes for the user. The user types the values in
the input boxes and then clicks a button. Input.asp then submits this
information to the Send.asp page for processing. To modify the Input.asp page,
follow these steps:
- In FrontPage, click the Input.asp file.
- On the Insert menu, point to
Form, and then click Form.
- On the Insert menu, point to
Form, and then click Text Box.
- Right-click the text box, and then click Form
Field Properties.
- In the Text Box Properties dialog box,
type number in the Name box, type
100 in the Width in characters box, and
then click OK.
- Clear the selection of the text box by pressing RIGHT
ARROW.
- On the Insert menu, point to
Form, and then click Text Box.
- Right-click the text box, and then click Form
Field Properties.
- In the Text Box Properties dialog box,
type cost in the Name box, type
100 in the Width in characters box, and
then click OK.
- Right-click the form, and then click Form
Properties.
- In the Form Properties dialog box, click
Send to other, and then click Options.
- In the Options for Custom Form Handler
dialog box, type send.asp in the Action
box.
- In the Method list, click Post, and then
click OK two times.
When viewed in HTML, the Input.asp page appears similar to the
following: <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<form method="POST" action="--WEBBOT-SELF--">
<!--webbot bot="SaveResults" u-file="A:\_private\form_results.csv" s-format="TEXT/CSV" s-label-fields="TRUE" startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--webbot bot="SaveResults" endspan i-checksum="43374" -->
<p><input type="text" name="number" size="100"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<form method="POST" action="send.asp">
<p><input type="text" name="cost" size="100"><input type="submit" value="Submit" name="B3"><input type="reset" value="Reset" name="B4"></p>
</form>
</body>
</html> Modify the Send.asp pageThe Send.asp page is sent the values to calculate from the
Input.asp page. Send.asp completes the calculation and then submits the
calculated total to the database. To modify the Send.asp page, follow these
steps:
- In FrontPage, click the Send.asp file.
- Click the Code tab on the bottom of the
page to switch to HTML view.
- Copy the following code, and then paste it above the
initial <html> tag at the top of the page:
<%
dim n, c, t
n = request("number")
c = request("cost")
t = c*n
%> Note You must include the"%" symbol at the beginning and end of the
code block, as illustrated in the previous code sample. The"%" symbol indicates
that the contained code is to be run as ASP code. - Click the Design tab on the bottom of the
page to switch to Normal view.
- On the Insert menu, point to
Form, and then click Form.
- Right-click the Reset button on the form,
and then click Cut.
- Click the Code tab on the bottom of the
page to switch to HTML view.
- Copy the following code, and then paste it immediately
after the <form method="POST" action="--WEBBOT-SELF--"> tag:
Thanks for the information. You input <%=Server.HTMLEncode(n)%> for the quantity, and <%=Server.HTMLEncode(c)%> for the cost. If this is correct, click Submit. - Click the Design tab on the bottom of the
page to switch to Normal view.
- Right-click the form, and then click Form
Properties.
- In the Form Properties dialog box, click
Advanced.
- In the Advanced Form Properties dialog
box, click Add.
- In the Name/Value Pair dialog box, type
cost in the Name box, and then type
<%=c%> in the Value box.
- Click OK.
- In the Advanced Form Properties dialog
box, click Add.
- In the Name/Value Pair dialog box, type
number in the Name box, and then type
<%=n%> in the Value box.
- Click OK.
- In the Advanced Form Properties dialog
box, click Add.
- In the Name/Value Pair dialog box, type
total in the Name box, and then type
<%=t%> in the Value box.
- Click OK two times.
- In the Form Properties dialog box, click
Send to database, and then click Options.
- In the Options for Saving Results to
Database dialog box, click Create Database, and then
click OK in the confirmation dialog box that appears.
- In the Options for Saving Results to
Database dialog box, click the Saved Fields tab.
Note that three database columns have been created that map to the
number, cost, and total form fields from the ASP pages. - Click OK two times.
- Save both pages.
- To publish the pages, click Publish Site
on the File menu.
- In the Publish Destination dialog box,
type the URL of your server, and then click OK.
- Test your pages, and then verify that the values and total
are inserted in the database.
REFERENCES
For additional information about how to use databases and ASP pages with
FrontPage , click the following article numbers to view the articles in the Microsoft Knowledge Base:
301986
FrontPage 2000 database
resource center
295192 What are Active Server Pages
297943 Getting started with Active Server Pages
For more information about how to publish a FrontPage
Web, click Microsoft Office FrontPage Help on the Help menu, type publish in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.
Modification Type: | Minor | Last Reviewed: | 5/2/2006 |
---|
Keywords: | kbForms kbProgramming kbDatabase kbASP kbhowto kbinfo KB823520 kbAudEndUser |
---|
|
|
©2004 Microsoft Corporation. All rights reserved.
|
|