Wintertree Software Inc.

Wintertree Spelling Server

Home Site index Contact us Catalog Shopping Cart Products Support Search

You are here: Home > Support > Wintertree Spelling Server > Submission mechanism in ASP Example 4


Explanation of the submission mechanism in ASP Example 4

This document describes how the submission mechanism operates in ASP Example 4. This example use a pop-up JavaScript form to interact with the user during the spelling-check process.

The pop-up form displayed by ASP Example 4 is generated by a server-side script which is independent from the invoking application (i.e., your application). This minimizes the number of connections between your application and Wintertree Spelling Server, and thereby simplifies development and maintenance of your application. However, it does require a somewhat tricky submission mechanism.

In the example, the spelling-check process begins when the user clicks the Check Spelling button on the form. Because the spelling check happens on the server, the form must be submitted so a server-side script (spellcheck.asp) can access the text fields and check their spelling. However, the form is also part of your application, and must therefore also be submitted to your application, for example when the user has completed filling in the form. Therefore, the form is submitted to the server for (at least) two purposes:

  1. To check the spelling of text areas on the form

  2. To submit the form to your application for processing

There may be other application-specific reasons for submitting the form to your application as well.

Normally, web forms are submitted to only one script on the server. Usually, the name of the script is specified using the ACTION attribute in the FORM tag:

<FORM ACTION="default.asp" METHOD="POST">

A form with this ACTION tag would always be submitted to default.asp, regardless of which submit-type button was pressed. Because we want the form to be submitted to spellcheck.asp when the Check Spelling button is pressed, a somewhat more sophisticated submission mechanism is required.

ASP Example 4 contains two submit-type buttons, one labelled Submit and the other Check Spelling. In your application, the Submit button is the one that causes the form to be submitted to your application's server-side script. Your application's form might have several buttons that cause it to be submitted to your application's server-side script. Later, we'll show how to cause each button to submit the form to your application's script.

The Submit and Check Spelling buttons are each linked to JavaScript functions via the ONCLICK attribute:

<INPUT TYPE=BUTTON NAME="Submit" VALUE="Submit" onClick="onSubmitBtn(0)">
<INPUT TYPE=BUTTON NAME="CheckSpelling" VALUE="Check Spelling" onClick="onCheckSpellingBtn(0)">

The Submit button is linked to a JavaScript function named onSubmitBtn, and the Check Spelling button is linked to onCheckSpellingBtn. When the Submit button is pressed by the user, the onSubmitBtn function is invoked. When the Check Spelling button is pressed, the onCheckSpellingBtn function is invoked. The onSubmitBtn and onCheckSpellingBtn functions are located in a file named SubmissionScript.js. These functions are run on the client system by the browser.

The ONCLICK attribute allows us to invoke some JavaScript code before the form is actually submitted. Usually, submit-type buttons in a form do not have a specific ONCLICK attribute. We define an ONCLICK attribute for the buttons because we want the form to be submitted to different scripts depending on which button was pressed.

The onCheckSpellingBtn function (which you'll recall is linked to the Check Spelling button) modifies the form's ACTION attribute so the form will be submitted to the spellcheck.asp script on the server. Once the ACTION attribute has been modified, it will remain that way until it is modified again. As it happens, the ACTION attribute will also be modified by the onSubmitBtn function (which is linked to the Submit button), which sets the ACTION attribute to default.asp so the form will be submitted to that script. Here's a synopsis of what happens when the Check Spelling button is pressed:

  1. Check Spelling button is pressed

  2. onCheckSpellingBtn function is run
  3. Form's ACTION attribute is set to spellcheck.asp
  4. Form is submitted (to spellcheck.asp)

The following happens when the Submit button is pressed:

  1. Submit button is pressed

  2. onSubmitBtn function is run
  3. Form's ACTION attribute is set to default.asp
  4. Form is submitted (to default.asp)

What if you add another submit-type button to your form? If you do not change the form's ACTION attribute, pressing the new button will submit the form to the default server-side script or to the last script it was submitted to. For example, if the user clicks the Check Spelling button, then clicks your new button, the form will be submitted to spellcheck.asp, which is probably not what you want. Why does this happen? Pressing the Check Spelling button changes the form's ACTION attribute to spellcheck.asp, and the ACTION attribute remains that way until it is set again. The solution is to link your new submit-type button to the onSubmitBtn function so the ACTION attribute will be set to default.asp before the form is submitted:

<INPUT TYPE=BUTTON NAME="NewSubmit" VALUE="New Submit" onClick="onSubmitBtn(0)">

(Of course, you would probably give your button a more descriptive label than "New Submit.") Now, when the New Submit button is clicked, the onSubmitBtn function will set the form's ACTION attribute to default.asp so the form would be submitted to that script. If you had several submit-type buttons, all would need to be linked to the onSubmitBtn function.

See also:


Home Site index Contact us Catalog Shopping Cart Products Support Search


Copyright © 2015 Wintertree Software Inc.