Option value Property - Change the value of a specific option element: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option

Description

Option value Property - Change the value of a specific option element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

Select your favorite fruit:
<select>
  <option id="myOption" value="a">Apple</option>
  <option value="orange">Orange</option>
</select>//from  w w w. ja v a2  s. com

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

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

<script>
function myFunction() {
    document.getElementById("myOption").value = "newValue";
    document.getElementById("demo").innerHTML = "changed";
}
</script>

</body>
</html>

Related Tutorials