title: Set selected default value of dropdown dynamically
body: <p>How to change default selected value in DropDownList using Javascript?</p>
  
  <p>I am new to JavaScript and i'm stuck at changing default selected value in dropdown list. 
  Here i want to change my default selected value "111" to the new value. It has to change after i enter the text e.g."abc" into the Modal and when i hit the "Ok" button.Now it has to display default selected("abc")in to the dropdown list which i get from the text box of the modal. And also the old values has not changed in the list.</p>
  
  <p>Code Snippet : </p>
  
  <pre><code>&lt;form&gt;
  &lt;select id="myList"&gt;
              &lt;option&gt;111&lt;/option&gt;
              &lt;option&gt;222&lt;/option&gt;
              &lt;option&gt;333&lt;/option&gt;
          &lt;/select&gt; &lt;br&gt;
          &lt;br&gt; 
  &lt;/form&gt;
  &lt;!-- Trigger/Open The Modal --&gt;
  &lt;button id="myBtn"&gt;Open Modal&lt;/button&gt;
  
  &lt;!-- The Modal --&gt;
  &lt;div id="myModal" class="modal"&gt;
  
    &lt;!-- Modal content --&gt;
    &lt;div class="modal-content"&gt;
      &lt;span class="close"&gt;&amp;times;&lt;/span&gt;
      &lt;input type="text" id="addtext" size="50" /&gt;&lt;br&gt;
      Write &amp; add text in the Dropdown list..&lt;/text&gt;
      &lt;br&gt;&lt;br&gt;
      &lt;button id="okBtn"&gt;OK&lt;/button&gt;
  
    &lt;/div&gt;
  
  &lt;/div&gt;
  
  &lt;script&gt;
  // Get the modal
  var modal = document.getElementById('myModal');
  
  // Get the button that opens the modal
  var btn = document.getElementById("myBtn");
  
  
  // Get the button that add text in the dropdown
  var btn1 = document.getElementById("okBtn");
  
  
  // Get the &lt;span&gt; element that closes the modal
  var span = document.getElementsByClassName("close")[0];
  
  // When the user clicks the button, open the modal 
  btn.onclick = function() {
      modal.style.display = "block";
  }
  
  btn1.onclick = function(){
      //var element = document.getElementById('addtext');
      var y = document.getElementById("addtext");
      var x = document.getElementById("myList");
      var option = document.createElement("option");
      option.text = y.value;
      x.add(option, option.defaultSelected, x[0] );
  
  
  
      modal.style.display = "none";
  
  }
  
  
  
  // When the user clicks on &lt;span&gt; (x), close the modal
  span.onclick = function() {
      modal.style.display = "none";
  }
  
  // When the user clicks anywhere outside of the modal, close it
  window.onclick = function(event) {
      if (event.target == modal) {
          modal.style.display = "none";
      }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I think i had done something wrong at </p>
  
  <pre><code>option.text = y.value;
      x.add(option, option.defaultSelected, x[0] );
  </code></pre>