HTML Code:
<!DOCTYPE html><!-- Define document type as HTML -->
<html><!-- Begin HTML document -->
<head><!-- Start of document header -->
<meta charset="utf-8"><!-- Define character encoding -->
<title>How to specify that the user is required to select a value before submitting the form</title><!-- Title of the HTML page -->
</head><!-- End of document header -->
<body><!-- Start of document body -->
<form method="post" action="https://www.w3resource.com/html-css-exercise/basic/solution/select-required-answer-demo.php"><!-- Start of form with method and action attributes -->
<select name="animals" required><!-- Start of dropdown menu with name and required attributes -->
<option value="">None</option><!-- Option for no selection -->
<option value="lion">Lion</option><!-- Option for Lion -->
<option value="tiger">Tiger</option><!-- Option for Tiger -->
<option value="elephant">Elephant</option><!-- Option for Elephant -->
</select><!-- End of dropdown menu -->
<input type="submit"><!-- Submit button for the form -->
</form><!-- End of form -->
</body><!-- End of document body -->
</html><!-- End of HTML document -->
Explanation:
Live Demo:
See the Pen select-required-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4