HTML form tag usage learning tutorial

HTML form tag usage learning tutorial

Forms in HTML can be used to collect various types of input information from users. A form is actually an area that contains form elements. The input information of various elements in this area will eventually be submitted to the program script through the form. For example, common ones include user login, registration, article publishing, etc., which are all submitted to the dynamic program for processing through forms. This section mainly discusses forms and form elements. How to submit form information to dynamic programs will be discussed in future programming language courses.
The form area is defined by the <form> tag. The values ​​of the elements in <form></form> will be submitted to the corresponding address through this form.

Input information
Generally, the <input> tag is used in forms to collect user input information, and the input type is determined by type.
The form tag used in most cases is the input tag (<input>). The input type is defined by the type attribute (type). Common input types include text fields, radio buttons, check boxes, drop-down menus, and so on.

Text Field
The text field can provide users with the function of inputting text. The browser will interpret the text field as a rectangular box. The user can move the cursor to the box and click to move the cursor into the box. Users can type letters, numbers, etc. into the form.
The text field is defined by setting the text value for the type attribute in the <input> tag.

XML/HTML CodeCopy content to clipboard
  1. < form >   
  2. Textfield 1: < input   type = "text" name = "firstname" />   
  3. Textfield 2: < input   type = "text" name = "lastname" />   
  4. </ form >   

The browser displays the following:
201678135308382.png (296×89)

Radio Button
Radio buttons mostly appear in the options when users enter information during registration. This type of button is used when users are only allowed to select one result.
A radio button is defined by setting the value of the type attribute in the <input> tag to radio.

XML/HTML CodeCopy content to clipboard
  1. < form >   
  2. < input   type = "radio" name = "sex" value = "male" /> Male
  3. < input   type = "radio" name = "sex" value = "female" /> Female
  4. </ form >   

The browser displays:
201678135342504.png (164×77)

Checkbox
Checkboxes allow users to select one or more options. A common feature is to provide users with functions such as remembering their login account when they log in. You can also collect multiple opinions from users on the user survey page.
To define a checkbox, set the value of the type attribute in the <input> tag to checkbox.

XML/HTML CodeCopy content to clipboard
  1. < form >   
  2. < input   type = "checkbox" name = "val1" />   
  3. Front-end developers are good
  4. < input   type = "checkbox" name = "val2" />   
  5. Front-end developers in general
  6. </ form >   

The browser displays the following:
201678135409883.png (203×92)

Drop-down menu
A drop-down menu is similar to a radio button in terms of information selection, but it can hold more information. And the drop-down menu can execute additional scripts after selecting the menu value.
The drop-down menu starts with the <select> tag, and each option tag in the select tag is a value in the drop-down menu.

XML/HTML CodeCopy content to clipboard
  1. < form >   
  2. < select   name = "cars" >   
  3. < option   value = "volvo" > Volvo </ option >   
  4. < option   value = "saab" > Saab </ option >   
  5. < option   value = "fiat" > Fiat </ option >   
  6. < option   value = "audi" > Audi </ option >   
  7. </ select >   
  8. </ form >   

The browser displays:
201678135442039.png (149×83)

Submit Button
A submit button is an essential part of every form. After the user has entered the corresponding information, he needs to trigger the action by clicking the Submit button to submit the form value to the next page. When the action attribute in the <form> tag is set to the corresponding submission address, the submit button will submit all the data obtained in the form to the page at this address.
The submit button is defined by setting the value of type to submit in the input tag. Below, taking the search box of the front-end developer as an example, set the submission address to the search page.

XML/HTML CodeCopy content to clipboard
  1. < form   name = "input" action = "http://www.frontopen.com/" method = "get" >   
  2. Keywords:
  3. < input   type = "text" name = "s" id = "s" />   
  4. < input   type = "submit" value = "search" />   
  5. </ form >   

The browser displays the following:
201678135509377.png (401×69)

Conclusion: This section only provides a basic demonstration and explanation of commonly used form front-end layout elements. Real form applications are mostly used in server programming languages ​​and require setting more parameters and rules. In this lesson, you only need to understand how to arrange the elements of the form. In most cases, you can basically cooperate with the backend programmers to complete the website development.

<<:  MySQL partition table is classified by month

>>:  JavaScript implements AI tic-tac-toe game through the maximum and minimum algorithm

Recommend

MySQL trigger trigger add, delete, modify and query operation example

This article uses examples to describe the add, d...

MySQL Server 8.0.13.0 Installation Tutorial with Pictures and Text

Install 8.0.13 based on MySQL 6.1.3. MySQL 8.0.13...

Installation and configuration method of vue-route routing management

introduce Vue Router is the official routing mana...

Tutorial on installing mongodb under linux

MongoDB is cross-platform and can be installed on...

How to change apt-get source in Ubuntu 18.04

When using apt-get to install, it will be very sl...

How to install Odoo12 development environment on Windows 10

Preface Since many friends say they don’t have Ma...

Tutorial on installing and uninstalling python3 under Centos7

1. Install Python 3 1. Install dependency package...

Four categories of CSS selectors: basic, combination, attribute, pseudo-class

What is a selector? The role of the selector is t...

JS implements a simple counter

Use HTML CSS and JavaScript to implement a simple...

When to use Map instead of plain JS objects

Table of contents 1. Map accepts any type of key ...

Tips for viewing History records and adding timestamps in Linux

Tips for viewing History records and adding times...

Detailed tutorial on installing phpMyAdmin on Ubuntu 18.04

We will install phpMyAdmin to work with Apache on...

Solve the problem of MySql8.0 checking transaction isolation level error

Table of contents MySql8.0 View transaction isola...