title: How to pass a selected drop down value to a function that changes background color onclick
body: <pre><code>&lt;script&gt;    
  myVar = document.getElementById('colorpick').value;
  
  function color_click(myVar){
  document.getElementById("touch").style.backgroundColor=myVar;
  }
  &lt;/script&gt;
  &lt;select name="colorpick" id="colorpick"&gt;
  &lt;option value="red"&gt;red&lt;/option&gt;
  &lt;option value="blue"&gt;blue&lt;/option&gt;
  &lt;option value="green"&gt;green&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;div id="touch" onclick="color_click(myVar);"&gt; XXXXXXXXXXX &lt;/div&gt;
  </code></pre>
  
  <p>This code works as expected when I substitute 'blue' for the value of myVar, however I want to choose which color via dropdown menu before I click the element to change it's background. </p>