How to preselect a value in a dropdown list of items in HTML forms?


With HTML, you can easily create a simple drop down list of items to get user input in HTML forms. A select box also called drop down box provides an option to list down various options in the form of drop down list.

You can also preselect a value in dropdown list of items in HTML forms. For that, add selected in the <option> tag for the value you want to preselect.

Example

You can try to run the following code to learn how to preselect value in a dropdown list of items works in HTML form −

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <title>Select Box Control</title>
   </head>
   <body>
      <p> Select any one:</p>
      <form>
         <select name = "dropdown">
            <option value = "Java" selected>Java</option>
            <option value = "Discrete Mathematics">Discrete Mathematics</option>
         </select>
      </form>
   </body>
</html>

Updated on: 18-Jun-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements