I want to invoke javascript function when value in the dropdown list changes. I dont want to hardcode dropdown list id .
Hence not using document.getElem
I don't know why do you need this onmousedown
event here, but what you have to do is put your function above actual usage. Look at the snipplet below:
<script type="text/javascript">
function jsFunction(value)
{
alert(value);
}
</script>
<select id ="ddl" name="ddl" onmousedown="this.value='';" onchange="jsFunction(this.value);">
<option value='1'>One</option>
<option value='2'>Two</option>
<option value='3'>Three</option>
</select>
using jQuery
$("#ddl").change(function () {
alert($(this).val());
});
jsFiddle
You just try this, Its so easy
<script>
$("#YourDropDownId").change(function () {
alert($("#YourDropDownId").val());
});
</script>
jsFunction is not in good closure. change to:
jsFunction = function(value)
{
alert(value);
}
and don't use global variables and functions, change it into module
Your code is working just fine, you have to declare javscript method before DOM ready.