How To Submit Form Data

Table of contents:

How To Submit Form Data
How To Submit Form Data

Video: How To Submit Form Data

Video: How To Submit Form Data
Video: Sending Form Data (POST) with the Fetch API in JavaScript 2024, May
Anonim

Sending data from a form filled out by a visitor to an Internet site is one of the most frequently solved tasks of interactive interaction between a web surfer and the server programs of this resource. Organization of this operation in the source code of the hypertext page is much easier than creating scripts to process the transmitted data. It can be implemented both by means of the HTML language and using JavaScript scripts.

How to submit form data
How to submit form data

Instructions

Step 1

If data processing is not carried out in the same file that generates the page with the form, be sure to specify the address of the handler script in the action attribute. Specify one of two possible methods for submitting form variables - Get or Post. The choice depends on which of them is used to read the variables by the script. In principle, this is enough to solve the problem; it is not necessary to place a special element in the form that initiates the sending of information, since pressing the Enter key by default is equivalent to clicking on the button for sending data. However, not every user will guess about this, so it is more preferable to place a corresponding button in the form.

Step 2

Use a button that is rendered by an input tag with a submit value in the type attribute. Clicking such a button is the "classic", most commonly used way of organizing the submission of data from a form in a web page. In addition to the type attribute, it is desirable to specify the value of the name attribute, and in the value you can put the text of the label on the button. For example:

Step 3

You can use JavaScript to send data. This can be useful in cases when you need to organize automatic dispatch on any event - for example, after the user selects the desired value in the drop-down list, or if it must be checked by a JavaScript validator before sending information. To implement this way of submitting data, use the submit method of the form object. For example, if the UniForm value is written to the name attribute of the form, then to simulate pressing the submit button in the JavaScript code, after all the necessary actions with the values entered by the user, you need to place the following line: document. UniForm.submit ();

Recommended: