Home Web Front-end HTML Tutorial What is the function of the name attribute in HTML? What is the default name attribute?

What is the function of the name attribute in HTML? What is the default name attribute?

Aug 27, 2018 pm 02:16 PM
html name

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">
Copy after login

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>
Copy after login

What is the effect of the code? Look at the picture

What is the function of the name attribute in HTML? What is the default name attribute?

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>
Copy after login

This picture What is the effect? ​​Let us take a look.

What is the function of the name attribute in HTML? What is the default name attribute?

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

#How to center the th header content in an html table? A detailed introduction to the align attribute of th header tag

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

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

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

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.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

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

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

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

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

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

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

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

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

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

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

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

See all articles