title: Javascript onchange event. select/option html dropdown input
body: <pre><code>var inputDrop = document.createElement('select');
  inputDrop.setAttribute("onchange", function test(){alert("test");});
  form.appendChild(inputDrop);
  
  
  var inputOpt1 = document.createElement('option');
  inputOpt1.value="1";
  inputOpt1.innerHTML="1";
  inputDrop.appendChild(inputOpt1);
  
  var inputOpt2 = document.createElement('option');
  inputOpt2.value="2";
  inputOpt2.innerHTML="2";
  inputDrop.appendChild(inputOpt2);
  
  form.appendChild(inputDrop);
  </code></pre>
  
  <p>I need to assign somekind of event handler to <strong>select</strong> dropdown input field with a number of options. I need to execute a function whenever a different option is selected. The above doesnt work and neither does <strong>inputDrop.onchange="alert('test')";</strong> not sure what im doing wrong here, please could someoneadvise?</p>
  
  <p>thanks.</p>