Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

check if select option is selected javascript

<select id="dropdown">
	<option value="" selected hidden>Select an option</option>
	<option value="1">One</option>
	<option value="2">Two</option>
	<option value="3">Three</option>
	<option value="4">Four</option>
	<option value="5">Five</option>
</select>
<script>
	const dropdown = document.getElementById("dropdown");
	// to check the dropdown's value at any time, use dropdown.value
	// because I've made a default option with no value, to check if
	// a value is selected simply do if (dropdown.value !== "") or
	// if (dropdown.value)
	dropdown.addEventListener("change", function() {
		console.log("Selected option element's value:", dropdown.value);
	});
</script>
 
PREVIOUS NEXT
Tagged: #check #select #option #selected #javascript
ADD COMMENT
Topic
Name
3+8 =