Microsoft KB Archive/319308

= How to complete mathematical calculations on a form before you send data to a database in FrontPage 2000 or FrontPage 2002 =

Article ID: 319308

Article Last Modified on 2/1/2007

-

APPLIES TO


 * Microsoft FrontPage 2002 Standard Edition
 * Microsoft FrontPage 2000 Standard Edition

-



This article was previously published under Q319308



IN THIS TASK

 * SUMMARY
 * Create the ASP Pages in FrontPage
 * Modify the Input.asp Page
 * Modify the Send.asp Page
 * REFERENCES



SUMMARY
In a Microsoft FrontPage 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 some 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 presented.

Create the ASP Pages in FrontPage

 * 1) Start FrontPage.
 * 2) On the File menu, click New, and then click Page or Web.
 * 3) On the File menu, click Save.
 * 4) In the Save As dialog box, type input.asp, and then click Save.
 * 5) On the File menu, click New, and then click Page or Web.
 * 6) In the New Page or Web task pane, click Blank Page.
 * 7) On the File menu, click Save.
 * 8) In the Save As dialog box, type send.asp, and then click Save.

back to top

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.

Note Make sure that you are in Normal view in FrontPage before you follow these steps.
 * 1) In FrontPage, select the Input.asp file.
 * 2) On the Insert menu, point to Form, and then click Form.
 * 3) On the Insert menu, point to Form, and then click Text Box.
 * 4) Right-click the text box, and then click Form Field Properties.
 * 5) 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.
 * 6) Clear the selection of the text box by pressing RIGHT ARROW.
 * 7) On the Insert menu, point to Form, and then click Text Box.
 * 8) Right-click the text box, and then click Form Field Properties.
 * 9) 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.
 * 10) Right-click the form, and then click Form Properties.
 * 11) In the Form Properties dialog box, click Send to other, and then click Options.
 * 12) In the Options for Custom Form Handler dialog box, type send.asp in the Action box.
 * 13) 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:

    New Page 1

    

back to the top

Modify the Send.asp Page
The 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.  In FrontPage, click the Send.asp file. Switch to HTML view.

To do so, click the HTML tab on the bottom of the page.</li>  Copy the following code, and then paste it above the initial tag at the top of the page: <%

dim n, c, t

n = request(&quot;number&quot;)

c = request(&quot;cost&quot;)

t = c*n

%> Note You must include the &quot;%&quot; symbol at the beginning and end of the code block, as illustrated in the preceding code sample. The &quot;%&quot; symbol indicates that the contained code is to be run as ASP code.

</li> Switch to Normal view.</li> On the Insert menu, point to Form, and then click Form.</li> Right-click the Reset button on the form, and then click Cut.</li> Switch to HTML view.</li>  Copy the following code, and then paste it immediately after the <form method=&quot;POST&quot; action=&quot;--WEBBOT-SELF--&quot;> tag: Thanks for the information. You input <%=Server.HTMLEncode(n)%> for the quantity, and <%=Server.HTMLEncode(c)%> for the cost. </li> Switch to Normal view.</li> Right-click the form, and then click Form Properties.</li> In the Form Properties dialog box, click Advanced.</li> In the Advanced Form Properties dialog box, click Add.</li> In the Name/Value Pair dialog box, type cost in the Name box, and then type <%=c%> in the Value box.</li> Click OK.</li> In the Advanced Form Properties dialog box, click Add.</li> In the Name/Value Pair dialog box, type number in the Name box, and then type <%=n%> in the Value box.</li> Click OK.</li> In the Advanced Form Properties dialog box, click Add.</li> <li>In the Name/Value Pair dialog box, type total in the Name box, and then type <%=t%> in the Value box.</li> <li>Click OK two times.</li> <li>In the Form Properties dialog box, click Send to database, and then click Options.</li> <li>In the Options for Saving Results to Database dialog box, click Create Database, and then click OK in the confirmation dialog box that appears.</li> <li>In the Options for Saving Results to Database dialog box, click the Saved Fields tab.

Note that three database columns have been created, mapping to the number, cost, and total form fields from the ASP pages.</li> <li>Click OK two times.</li> <li>Save both pages.</li> <li>To publish the pages, click Publish Web on the File menu.</li> <li>In the Publish Destination dialog box, type the URL of your server, and then click OK.</li> <li>Test your pages, and then verify that the values and total are inserted into the database.</li></ol>

back to the top

<div class="references_section">