Answers for "drop down list javascript"

9

html create drop down list

<html>
 <head>
   <title>Selection Inputs</title>
 </head>
 <body>
   <form>
     <label for="selector"> <!-- Can add label if want -->
       <p>A "select" element allows users to input from a selection:</p>
       <select id="selector"> <!-- Use "select" to create object -->
         <option>Option 1</option> <!-- Add all applicable options -->
         <option>Option 2</option>
         <option selected>Option 3</option> <!-- add selected to change default from first option -->
         <optgroup label="Group"> <!-- To create nested options for categories use "optgroup" -->
           <option>Option 4</option>
           <option>Option 5</option>
       </select>
     </label>
   </form>
 </body>
</html>
Posted by: Guest on March-10-2020
0

dropdown list using js

<!DOCTYPE html>
<html>
<body>

<form>
  Select your favorite browser:
  <select id="myList" onchange="myFunction()">
    <option></option>
    <option>Google Chrome</option>
    <option>Firefox</option>  
    <option>Internet Explorer</option>
    <option>Safari</option>
    <option>Opera</option>
  </select>
<p>Your favorite browser is: <input type="text" id="demo" size="20"></p>
</form>
<script>
function myFunction() {
  var mylist = document.getElementById("myList");
  document.getElementById("demo").value = mylist.options[mylist.selectedIndex].text;
}
</script>
</body>
</html>
Posted by: Guest on February-19-2021

Browse Popular Code Answers by Language