How To Pass A Checkbox

Table of contents:

How To Pass A Checkbox
How To Pass A Checkbox

Video: How To Pass A Checkbox

Video: How To Pass A Checkbox
Video: How to Use Excel Checkboxes | Interactive Checklists u0026 Reports 2024, May
Anonim

Checkboxes are form elements in which the user can check or uncheck them. They are often called "flags" and are used as a trigger that allows you to get one of two answers - "yes" or "no". Most often, the question of passing checkbox values arises when novice programmers create forms in hypertext documents. Below is the minimum set of tags necessary for solving this problem, which should be placed in such a document.

How to pass a checkbox
How to pass a checkbox

Instructions

Step 1

Place the form tag in the document - its attributes should contain information about which method and to which address the data of all form elements, including checkboxes, will be sent. Enter the address of the data handler script in the action attribute, and the data transfer method in the method attribute. The value of the action attribute can be left blank if the page from which the information is sent is itself a handler script. Two values are valid for the data transfer method - Get and Post. The choice depends on which of these options is programmed to read the received data in the handler script. The complete form tag with the minimum required set of attributes may look like this:

Step 2

Enter the required number of selection items (checkboxes) between the opening and closing form tags. This is done using input tags, in the type attribute of which the checkbox value is written. Each of them must contain at least two required attributes - name and value. Pay attention to the name attribute - unlike grouped selection elements (radio), the name values for each checkbox should be different. The word placed in this attribute will be used as the name of the variable passed from the form. The value of the value attribute will be assigned to the variable with this name. Such a group of tags in a form might look like this:

Step 3

Place a button in front of the form's closing tag that, when clicked, will send the user-selected checkbox value to the address specified in the form's opening tag. Do this using the input tag, placing the value submit in the type attribute. In addition to this attribute, you can also add value by entering text there to display it on the button for sending data. The complete code that will send the information of the checkbox selected by the visitor to the handler script may look, for example, like this:

Recommended: