I’m learning Javascript, and here’s what I’m trying to do…
<body>
<select name="selTitle" id="titles">
<option value="Mr.">Mr.</option>
<option value="Ms.">Ms.</option>
</select>
</body>
and for the script,
<script type='text/javascript'>
var title = document.getElementById("titles");
title.onchange = function() {
alert("Hi");
}
</script>
But its not working, am I doing something wrong? Here’s the demo.. http://jsfiddle.net/jq9UA/10/
Wrap your code in
onloadevent:Working Demo
This makes sure that select box is actually available to apply events to which you can do using
onloadevent or puting your script at bottom of your page just before</body>tag.