I am trying to learn the onChange function. I grabbed this code and implemented it on my site and it is working, it actually shows the value of what the user has chosen but when I try to console log the variable in chrome it says:
Uncaught ReferenceError: x is not defined. Why is that? Why is the variable not defined even after that I have chosen a car. And one more question. Is this javascript or Jquery?
The CODE
<!DOCTYPE html>
<html>
<body>
<p>Select a new car from the list.</p>
<select id="mySelect" onchange="myFunction()">
<option value="Audi">Audi
<option value="BMW">BMW
<option value="Mercedes">Mercedes
<option value="Volvo">Volvo
</select>
<p>When you select a new car, a function is triggered which outputs the value of the selected car.</p>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("mySelect").value;
document.getElementById("demo").innerHTML = "You selected: " + x;
}
</script>
</body>
</html>
<option value="Audi">Audi</option>