Select value Property - Return the value of a selected option in a drop-down list: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Select

Description

Select value Property - Return the value of a selected option in a drop-down list:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form>
Select your favorite fruit:
<select id="mySelect">
  <option value="a">Apple</option>
  <option value="orange">Orange</option>
  <option value="pineapple">Pineapple</option>
  <option value="banana">Banana</option>
</select>/*from  ww  w.  ja  va  2  s  . co m*/
</form>

<button type="button" onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("mySelect").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials