Skip to content
Advertisement

call javascript function onchange event of dropdown list

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.getElementById

My Code:

<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>

function jsFunction(value)
{
    alert(value);
}

This is giving error ReferenceError: jsFunction is not defined

Fiddle : http://jsfiddle.net/6uyz4b8x/1/

Advertisement

Answer

Your code is working just fine, you have to declare javscript method before DOM ready.

your working example

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement