Search
 
SCRIPT & CODE EXAMPLE
 

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>
Comment

PREVIOUS NEXT
Code Example
Html :: inline bootstrap 
Html :: navba using bootstrap 
Html :: html.erb conditionally add class 
Html :: add csrf token in vuejs 
Html :: text inside input 
Html :: html iframe example 
Html :: how to make a clickable link 
Html :: a href to other site 
Html :: how to formate text in div 
Html :: svg rounded corners 
Html :: how to add css to html 
Html :: bootstrap undismissable modal 
Html :: button float right 
Html :: html images with link 
Html :: open link in new tab 
Html :: v-on hover 
Html :: javascript on lose focus 
Html :: how to get number list in html 
Html :: how to choose multiple option from select option 
Html :: svelte comments 
Html :: text monospace bootstrap 
Html :: html img tag with alt 
Html :: Prettier not formatting HTML files in VS Code 
Html :: how to make anchor tag open in new tab 
Html :: input month in html 
Html :: Chakra ui center content table 
Html :: divider bootsrap 
Html :: how to write superscript in markdown 
Html :: range html 
Html :: html to pdf angular 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =