search
HomeWeb Front-endHTML TutorialWhat 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

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>

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
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
The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.