title: Javascript select element to string comparison
body: <p>Below Code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;select name="cars" id="demo1"&gt;
  &lt;option value="Volvo"&gt;Volvo&lt;/option&gt;
  &lt;option value="Car"&gt;Car&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;button onclick="myFunction()"&gt;Try it&lt;/button&gt;
  
  &lt;script&gt;
      function myFunction() {
          var compare = 'Volvo';
          var e = document.getElementById("demo1");
          var val = e.options[e.selectedIndex].value;
  
          if (val == compare) {
              alert(val);
          }
       }
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In the above, if I select 'Volvo' from the list and click on "Try it" button it should compare the selected value(here the value is "Volvo") with "Volvo" in javascript and alert the selected value but the "IF" condition in javascript always fails.</p>
  
  <p>Can anyone spot the bug in the code?</p>
  
  <p>Thanks,
  ADI</p>