title: Set dropdown value based on what is selected in another dropdown using Javascript
body: <p>I have couple of drop downs whose values are readily available as below.</p>
  
  <p>Dropdown 1:</p>
  
  <pre><code>&lt;select id="a"&gt;
    &lt;option value="1"&gt;Bike&lt;/option&gt;
    &lt;option value="2"&gt;Car&lt;/option&gt;
    &lt;option value="3"&gt;Bus&lt;/option&gt;
    &lt;option value="4"&gt;Cycle&lt;/option&gt;
    &lt;option value="5"&gt;Wagon&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Dropdown 2: </p>
  
  <pre><code>&lt;select id="b"&gt;
    &lt;option value="1"&gt;2 wheel&lt;/option&gt;
    &lt;option value="2"&gt;4 wheel&lt;/option&gt;
    &lt;option value="3"&gt;6 wheel&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>I need to change second dropdown value based on the selected value from first dropdown. For example: </p>
  
  <ul>
  <li>If Bike or Cycle is selected from dropdown 1, 2 wheel should be auto selected </li>
  <li>If Car or Wagon is selected, 4 wheel should be auto selected.</li>
  </ul>
  
  <p>Only option available for me is to use JavaScript. I tried like below, but it isn't working. Please help pointing out what am I missing/doing incorrect.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;select id="a" onchange="change();"&gt;
    &lt;option value="1"&gt;Bike&lt;/option&gt;
    &lt;option value="2"&gt;Car&lt;/option&gt;
    &lt;option value="3"&gt;Bus&lt;/option&gt;
    &lt;option value="4"&gt;Cycle&lt;/option&gt;
    &lt;option value="5"&gt;Wagon&lt;/option&gt;
  &lt;/select&gt;
  &lt;select id="b"&gt;
    &lt;option value="1"&gt;2 wheel&lt;/option&gt;
    &lt;option value="2"&gt;4 wheel&lt;/option&gt;
    &lt;option value="3"&gt;6 wheel&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>function change() {
  if (document.getElementById('a').value == '1')
    document.getElementById("b").value = '1';
  else if (document.getElementById('a').value == '2')
    document.getElementById("b").value = '2';
  else if (document.getElementById('a').value == '3')
    document.getElementById("b").value = '3';
  else if (document.getElementById('a').value == '4')
    document.getElementById("b").value = '1';
  else if (document.getElementById('a').value == '5')
    document.getElementById("b").value = '2';
  };
  </code></pre>
  
  <p>EDIT: To be more specfic about what I need, I edited the example above.</p>