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

Detailed explanation of JS ES6 coding standards

Table of contents 1. Block scope 1.1. let replace...

MySQL 8.0.19 installation detailed tutorial (windows 64 bit)

Table of contents Initialize MySQL Install MySQL ...

Syntax alias problem based on delete in mysql

Table of contents MySQL delete syntax alias probl...

JS implements the sample code of decimal conversion to hexadecimal

Preface When we write code, we occasionally encou...

Steps for Vue3 to use mitt for component communication

Table of contents 1. Installation 2. Import into ...

CSS3 analysis of the steps for making Douyin LOGO

"Tik Tok" is also very popular and is s...

Vue implements user login and token verification

In the case of complete separation of the front-e...

Beginners learn some HTML tags (2)

Related article: Beginners learn some HTML tags (1...

How to decompress multiple files using the unzip command in Linux

Solution to the problem that there is no unzip co...

How to underline the a tag and change the color before and after clicking

Copy code The code is as follows: a:link { font-s...

Node.js+express message board function implementation example

Table of contents Message Board Required librarie...

Tutorial on installing mysql5.7.18 on mac os10.12

I searched the entire web and found all kinds of ...