Horje
How to Allow Multiple Selection in HTML Option Value

Use the multiple attribute to allow the user to select more than one value:


Simple Example of Allowing Multiple Selections:

<label for="cars">Choose a car:</label>
<select id="cars" name="cars" size="4" multiple>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="fiat">Fiat</option>
  <option value="audi">Audi</option>
</select>

Full Example of Allowing Multiple Selections:

Allow Multiple Selections Use the multiple attribute to allow the user to select more than one value.
index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<h2>Allow Multiple Selections</h2>

<p>Use the multiple attribute to allow the user to select more than one value.</p>

<form action="/action_page.php">
  <label for="cars">Choose a car:</label>
  <select id="cars" name="cars" size="4" multiple>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="fiat">Fiat</option>
    <option value="audi">Audi</option>
  </select><br><br>
  <input type="submit">
</form>

<p>Hold down the Ctrl (windows) / Command (Mac) button to select multiple options.</p>

</body>
</html>

Output should be:

Full Example of Allowing Multiple Selections:

Hold down the Ctrl (windows) / Command (Mac) button to select multiple options.





Category:
Web Tutorial
Sub Category:
HTML Form Elements
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference