This article mainly introduces the usage of the name attribute of the HTML form tag. Finally, it also talks about the difference between name and id. This article talks about the advantages of the name tag. Now let us take a look at it. Let’s write an article
Let’s first take a look at the usage of the name attribute of the HTML form tag:
The name attribute in the form is mainly used to mark the form, like Each of us has the same name. When the form has a name, we can use the request.form("name") method to obtain the relevant data in the form when designing dynamic web pages!
Look at the example introduction of the name attribute of the form tag:
HTML form with name attribute:
<form action="form_action.asp"method="get"name="myForm"> <p>请输用户名: <input type="text"name="fname"/></p> <p>再输用户名: <input type="text"name="lname"/></p> <input type="button"onclick="formSubmit()"value="确定提交吗"/> </form>
The effect is as shown in the figure:
Introduction to the name attribute of the form tag:
1. If the name attribute is given to [], the name attribute will be added when submitting the form. Name values are automatically formed into an array for submission
2. The size attribute is expressed as two attributes, one is type as text and password, size is expressed as the width of the visible content, and other types of input boxes are expressed in pixels. Unit input field width; common usage:
<p>PIN:<input type="text" name="pin" maxlength="2" size="2"/></p>
Use maxlength with the size attribute for direct layout
3. Note that the size attribute has compatibility issues, generally do not use it, try to use css to control the input Width
The following describes the usage of the commonly used name attribute but rarely used id attribute: (The difference between name and id, the advantages of name)
form tag The name attribute was originally for identification purposes, but now according to the specification, it is recommended to use id to identify elements. However, name cannot be replaced in the following uses:
1. The name of the control in the form, and the submitted data is controlled by the name of the control instead of the id. Because there are many names that correspond to multiple controls at the same time, such as checkbox and radio, and the ID must be unique in the entire document. In addition, the browser will set the request sent to the server based on the name. Therefore, if you use id, the server cannot get the data.
2. The names of frames and windows are used to specify targets in other frames or windows.
The following points can be used universally, but it is strongly recommended to use the id instead of the name attribute:
Anchor point, usually written as
<a name="myname">
can now be specified with any element id :
<div id="myid">
Okay, the above is an introduction to the name attribute of the HTML form tag. If you have any questions, you can ask below
[Editor’s recommendation]
## What does the #HTML ul tag mean? Detailed explanation of the role of HTML ul tag
How to wrap the text in the pre tag in html? Usage examples of html pre tag
The above is the detailed content of How to use the name attribute of html form tag? Detailed explanation of the name attribute of form tag. For more information, please follow other related articles on the PHP Chinese website!