title: keep selected value from dropdown after postback by javascript
body: <p>I want to Retain dropdownlist selected value after postback, I am trying hard to understand how to retain a dropdownlist selected value after postback.</p>
  
  <p>on this function I get selected values from dropdownlist and  I save it in local storage:</p>
  
  <pre><code>document.onreadystatechange = function () {
      if (document.readyState === 'complete') {
          window.localStorage.setItem("Rooms", $("#Rooms option:selected").val());
          window.localStorage.setItem("Persons", $("#Persons option:selected").val());
          window.localStorage.setItem("Childrens", $("#Childrens option:selected").val());
      }
  }
  </code></pre>
  
  <p>on page load I have <code>adddate()</code> function called:</p>
  
  <pre><code>function AddDate() {
      var date = moment();
  
      document.getElementById('Arrival').value = date.format('DD/MM/YYYY');
      document.getElementById('Departure').value = date.add(1, 'days').format('DD/MM/YYYY');
      $("#Arrival").val(window.localStorage.getItem("Arrival"));
      $("#Departure").val(window.localStorage.getItem("Departure"));
      $("#Rooms option:selected").val(window.localStorage.getItem("Rooms"));
      $("#Persons option:selected").val(window.localStorage.getItem("Persons"));
      $("#Childrens    option:selected").val(window.localStorage.getItem("Childrens"));
  }; 
  window.onload = AddDate;
  </code></pre>
  
  <p>below is my select list:</p>
  
  <pre><code>&lt;select id="Rooms" name="Rooms" class="dropdown"&gt;
      @for (int i = 1; i &lt;= Model.MaximumNumberOfRooms; i++){
          &lt;option value="@i"&gt;@i&lt;/option&gt;
      }
  &lt;/select&gt;
  </code></pre>
  
  <p>I have tried with many options which did not work</p>
  
  <p>Do you have any suggestion? Thanks.</p>