title: Change Select tag value using JavaScript
body: <p>I'm trying to change a value from a select tag using JavaScript. Let's say that I have this textbox, and if that textbox is null, no changes will be done and the value of the select tag options will be as is. But if that textbox is filled, then I have to assign a different value aside from the ones in the select tag options. </p>
  
  <p>Here's what I'm trying to do:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;input type="text" id="txtTest" /&gt;
  &lt;select name="rdoSelect" id="rdoSelect"&gt;
    &lt;option value="option1"&gt;Option 1&lt;/option&gt;
    &lt;option value="option2"&gt;Option 2&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>JavaScript:</p>
  
  <pre><code>if (document.getElementById('txtTest').value===null)
  {
      document.getElementById('rdoSelect').value;
  }
  else
  {
      document.getElementById('rdoSelect').value = "option 3";
  }
  </code></pre>
  
  <p>I can't make it work. I've tried pointing it to an element/variable rather than to a value and it still doesn't work:</p>
  
  <pre><code>var test = document.getElementById('rdoSelect');
  test.value = "option 3";
  </code></pre>
  
  <p>I need help, please. Thanks!</p>