title: JavaScript Alert Selected Option of html drop down
body: <p>I have searched around and tried various things but I cannot find a way to get javascript to alert my chosen option. All that happens with what I have is in the console debugging section at the bottom of the page it says " 'null' is not an object (evaluating 'x.options') " which suggests to me that my variable x is not getting any value in the first place, here is my code:</p>
  
  <p>html</p>
  
  <pre><code>    &lt;select id=“test-dropdown” onchange=“choice1()”&gt;
  
      &lt;option value=“1”&gt;One&lt;/option&gt;
  
      &lt;option value=“2”&gt;Two&lt;/option&gt;
  
      &lt;option value=“3”&gt;Three&lt;/option&gt;
  
      &lt;/select&gt;
  </code></pre>
  
  <p>javascript</p>
  
  <pre><code>    function choice1()
      {
      var x = document.getElementById(“test-dropdown”);
      alert(x.options[x.selectedIndex].value);
      }
  </code></pre>
  
  <p>I would be very thankful if someone could solve the problem or point me in the direction of where this question has been answered before.</p>