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

Vue implements a simple calculator

This article example shares the specific code of ...

mysql5.7.20 installation and configuration method graphic tutorial (mac)

MySQL 5.7.20 installation and configuration metho...

CSS warped shadow implementation code

This article introduces the implementation code o...

MySQL5.7 master-slave configuration example analysis

MySQL5.7 master-slave configuration implementatio...

JavaScript drag time drag case detailed explanation

Table of contents DragEvent Interface DataTransfe...

Docker container log analysis

View container logs First, use docker run -it --r...

Detailed tutorial on downloading mysql on Windows 10

MySQL versions are divided into Enterprise Editio...

vue-cli configuration uses Vuex's full process record

Table of contents Preface Installation and Usage ...

JavaScript implements checkbox selection function

This article example shares the specific code of ...

HTML meta explained

Introduction The meta tag is an auxiliary tag in ...

Detailed explanation of the life cycle of Angular components (Part 2)

Table of contents 1. View hook 1. Things to note ...

Summary of the main attributes of the body tag

bgcolor="text color" background="ba...

ElementUI implements the el-form form reset function button

Table of contents Business scenario: Effect demon...