


What is the function of the name attribute in HTML? What is the default name attribute?
This article mainly introduces the name attribute of the form in HTML, including basic definitions and example renderings, as well as explanations of the role of the name attribute in HTML, and examples of the name attribute in the form.
Let’s first understand the definition of the name attribute in the form:
The name attribute specifies the name of the input element.
The name attribute is used to identify the form data after it is submitted to the server
or reference the form data through JavaScript on the client.
Note: Only form elements with the name attribute set can pass their values when submitting the form.
<input name="value">
Look at an example to help you understand the above definition better
HTML form with two text fields and a submit button:
<form action="form_action.asp" method="get"> <p>name: <input type="text" name="fullname" /></p> <p>email: <input type="text" name="email" /></p> <input type="submit" value="Submit" /> </form>
What is the effect of the code? Look at the picture
Having said so much, everyone should have some understanding of the name attribute, so now let’s talk about the role of the name attribute in HTMLBar
If you use request.form("name") when submitting the form, you can get the value entered in your text box. If there are multiple controls on your page with the same name, then You can get an array using getelementsbyname. Also, if there are two radios on your page that allow users to choose gender, if you do not set the name attribute for these two buttons, you can try what effect it will have. Radio can be used to allow users to select gender. Generally, when selecting gender, only one can be selected. If you do not set the names of the two radios to be the same, then he will be able to select both male and female, so The name attribute is very important in the form.
Having said so much, let’s look at an example code of the role of the name attribute:
<html> <select> <option value="1">php中文网</option> <option value="2" selected="selected">百度</option> <option value="3">腾讯</option> </select> <form> <input type="checkbox" name="newsletter" checked="checked" value="Daily" />非常喜欢 <input type="checkbox" name="newsletter" value="Weekly" />喜欢 <input type="checkbox" name="newsletter" checked="checked" value="Monthly" />还行 </form> <input type="button" value="确定"/> <SPAN style="WHITE-SPACE: pre"> <input type="text" value="请输入原因"/> </SPAN> </html>
This picture What is the effect? Let us take a look.
The name attribute is the name of the control (multiple controls can have the same name), and the value is the name of the control. Value
Not all values of controls will be displayed
After defining the name and value of the control, you can obtain the control and its value on the server
I didn’t see it The name of submit does not mean that the browser ignores its name. It is also defined by the browser before submission. Its name and value can also be obtained on the server.
The control does not define name/value It can also be displayed. Its name/value is defined just for the convenience of receiving and distinguishing it on the server. Of course, the value of the button is not only to store its value, but also to display it.
Okay, that’s it. The entire content of the article is here. If you have any questions, please feel free to ask below
[Related recommendations]
What does the head tag in HTML mean? An article teaches you how to use the head tag correctly
The above is the detailed content of What is the function of the name attribute in HTML? What is the default name attribute?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.
