title: Javascript: Change select background-color if option is selected
body: <p>I'm searching a while for a Javascript function that changes the background-color of my select field if an option is selected.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;select name="classNumber" id="classNumber"&gt;
   &lt;option selected disabled value="0"&gt;Bitte Klasse auswählen&lt;/option&gt;
   &lt;option value="5"&gt;5&lt;/option&gt;
   &lt;option value="6"&gt;6&lt;/option&gt;
   &lt;option value="7"&gt;7&lt;/option&gt;
   &lt;option value="8"&gt;8&lt;/option&gt;
   &lt;option value="9"&gt;9&lt;/option&gt;
   &lt;option value="10"&gt;10&lt;/option&gt;
   &lt;option value="11"&gt;11&lt;/option&gt;
   &lt;option value="12"&gt;12&lt;/option&gt;
   &lt;option value="13"&gt;13&lt;/option&gt;
  &lt;/select&gt;
  &lt;select name="classSpecify" id="classSpecify"&gt;
   &lt;option selected disabled value="0"&gt;Bitte Klasse spezifizieren&lt;/option&gt;
   &lt;option value="A"&gt;A&lt;/option&gt;
   &lt;option value="B"&gt;B&lt;/option&gt;
   &lt;option value="D"&gt;C&lt;/option&gt;
   &lt;option value="D"&gt;D&lt;/option&gt;
   &lt;option value="N"&gt;N (Naturwissenschaftliches Profil)&lt;/option&gt;
   &lt;option value="S"&gt;S (Sprachliches Profil)&lt;/option&gt;
   &lt;option value="G"&gt;G (Gesellschaftliches Profil)&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Javascript that is not working, at this time just for testing I set up just one select:</p>
  
  <pre><code>var classNumber = document.getElementById('classNumber');
  var first = classNumber.options[classNumber.selectedIndex].value;
  if (first != 0) {
      alert('Test');
      document.getElementById('classNumber').style.background="$green";
  };
  </code></pre>