Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App
Next Article:
How to disable the drop-down list in HTML5 ?
Next article icon

How to specify the name for drop-down list in HTML5 ?

Last Updated : 26 Mar, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Drop-down lists are also another way to allow people to choose only one choice from a number of alternatives. Since the default option is usually the first item on the list, using the drop-down list can be a safe choice if you know that one option is always preferred over the others. The drop-down list can only be used when the user must pick between choices since it does not provide the user with the option of not selecting something. In HTML 5, the name attribute defines the name of a drop-down list. After a form has been entered, the name attribute in JavaScript is used to refer to elements or form data.

Syntax:

<select>     <option value=””>option1</option>     <option value=””>option2</option>  </select>

<select> is a tag used to construct a dropdown list, as seen in the above code. The <option> tag, which is embedded in the select tag, is an attribute value or attributes for the selection list, with the value representing whether the option is chosen, disabled, or has certain other properties. We can use CSS to show our selection list effects and set positions like this.

Attributes: The following are some of the attributes that are included in the <select> tag

  • Name: This attribute is useful for naming a control that will be sent to the server to be detected and to receive necessary value.
  • Multiple:The user will pick several values from the selector list if the attribute is set to “multiple.”
  • Size: The Size parameter determines the size of the scrolling box that covers the Dropdown list. It's also useful for highlighting multiple choices from a list.
  • Value: This attribute indicates whether a choice in the selection list has been chosen.
  • Selected: Selected attributes allow the display of already selected list items from the list at the very beginning of page loads.
  • Label: Label attribute works as another approach for labeling options value.
  • Disabled: If we want a drop-down list with a disable option, we can use the disabled attribute in the HTML select list.
  • onChange:When a user selects a choice from a dropdown list, an event is triggered on item selection.
  • onFocus: When the user hovers the mouse over a selection list option to pick it, an event is triggered to select the object.
  • Form: This attribute is used to specify one or more similar types to the select field.
  • disabled: With the support of this attribute, we will keep our drop-down list hidden from the user.
  • required: When filling out a form, we want to make it clear that this field allows the user to choose some value from a list before submitting the form, so in this situation, we define that the user must choose any value from the list.

Examples 1: Below is the code that illustrates a drop-down list with a name attribute.

HTML
<!DOCTYPE html> <html>    <body style="text-align:center;">   <h1>GeeksForGeeks Practice</h1>   <h2>GFG Courses</h2>    <form action="/action_page.php">     <label for="course">       Select a course from drop-down list :     </label>          <select name="course" id="course">       <option value="1">         Getting Started with C       </option>        <option value="2">         DSA Self-Paced       </option>        <option value="3">         Complete Interview Preparation       </option>        <option value="4">         Java Collections       </option>        <option value="5">         30 Days Of Code       </option>     </select>     <br><br>     <input type="submit" value="Submit">   </form> </body>  </html> 


Output:

Output

Example 2:

HTML
<!DOCTYPE html> <html>  <head>   <style>       body{         background-color: lightblue;}       h1{         color: green;         text-align: center;       }       h2{         color: yellow;         text-align: center;       }       p{         font-family: verdana;         font-size: 20px;       }   </style> </head>  <body>   <h1>GeeksForGeeks</h1>   <h2>GFG Contest</h2>   <h3>"Coding Question of the Day"</h3>     <p>     Given a sorted deck of cards numbered 1 to N.<br>     1) We pick up 1 card and put         it on the back of the deck.<br><br>     2) Now, we pick up another card,         it turns out the deck..<br><br>   </p>     <form action="/action_page.php">     <label for="course">       Choose a Programming Language :     </label>     <select name="course" id="course">       <option value="1">C++</option>       <option value="2">C</option>       <option value="3">JAVA</option>       <option value="4">Python</option>       <option value="5">C#</option>     </select><br><br>     <input type="submit" value="Select">   </form> </body>  </html> 


Output:


Next Article
How to disable the drop-down list in HTML5 ?
author
piyushkr2022
Improve
Article Tags :
  • Web Technologies
  • HTML
  • HTML5
  • HTML-Tags
  • HTML-Attributes
  • HTML-Questions

Similar Reads

  • How to disable the drop-down list in HTML5 ?
    In this article, we will learn how to disable the drop-down list in HTML5. The drop-down is used to create a list of items that need to select an element. We use <select> and <option> elements to create a drop-down list and use the disabled attribute in <select> element to disable
    2 min read
  • How to specify a name for the output element in HTML?
    The name attribute specifies the name of an <output> element. It is used to reference form data after it has been submitted, or to reference the element in JavaScript. The <output> tag is used to represent the result of a calculation. The HTML <for> type attribute is used because i
    1 min read
  • How to set a name for the metadata in HTML5 ?
    The metadata means the information about data. The <meta> tag in HTML provides information about HTML document or in simple words, it provides important information about a document. These tags are basically used to add name/value pairs to describe properties of HTML documents, such as expiry
    1 min read
  • How to specify a name for the fieldset using HTML ?
    The <fieldset> tag in HTML5 is used to make a group of related elements in the form and it creates the box over the elements. The <fieldset> tag is new in HTML5. The HTML <fieldset> name attribute is used to specify the name for the fieldset element. It is used to reference the for
    1 min read
  • How to specify multiple forms the select field belongs to in HTML ?
    The task is to specify multiple forms the select field belongs to. In simple wording, we have to find out which form the specific select belongs to. You can achieve this task by using the form attribute. select element - It is used to create a drop-down list in HTML.form element - It is used to crea
    2 min read
  • How to specify a label for an optgroup tag in HTML5 ?
    The HTML <optgroup> element creates a grouping of options within a <select> element. The HTML <optgroup> label Attribute text is used to specify a label for an option-group. The disabled attribute is used to specify that an option-group should be disabled. Syntax: <optgroup labe
    1 min read
  • How to define a drop-down list in HTML5 ?
    In this article, we define a Drop-Down List By using the <select> Element in the Document. This tag is used to create a drop-down list. The <select> tag contains <option> tag to display the available option of drop-down list.Note: The tag is used in a form to receive user response.
    1 min read
  • How to specify a shorter label for an option in HTML5 ?
    The HTML option label attribute specifies the text value that defines the option's shorted label. In the drop-down list, the shorter version will be shown. An object stored in a <select>, <optgroup>, or <datalist> element is defined by the HTML <option> element. As a result,
    2 min read
  • How to set the focus on drop-down list automatically when the page loads in HTML5?
    The purpose of this article is to focus the drop-down list automatically when the page loads in HTML5. The <select> autofocus attribute is a boolean attribute that specifies that the drop-down list should automatically get focus when the page loads. Syntax: <select autofocus> Example: Th
    1 min read
  • How to set the name for the object in HTML5?
    <object> element in HTML5 is used to link any external files and resources in the form of any image or any nested linked webpages or content or any plugin that can do the same work. Syntax: <object name="name"></object>Elementary uses of <object/ element: Initially <object
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences