title: Automatic form fill using javascript
body: <p>here is my code:
      </p>
  
  <pre><code>function setActualDate()
  {
  var d1 = new Date();
  var y = d1.getFullYear();
  var d = d1.getDate();
  var m1 = d1.getMonth() + 1;
  var m2 = d1.getMonth();
  
  document.getElementById('entryDate').value = (y+"-"+m1+"-"+d);
  document.getElementById('selectedYear').value = y;
  document.getElementById('selectedMonth').value = ("0"+m2);
  }
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body onload="setActualDate()"&gt;
  &lt;div id="page"&gt;
  &lt;h3&gt; Welcome to Money Logger!&lt;/h3&gt;
  
  &lt;form name="enter" action="enter.php" method="post"&gt;
  Enter
  &lt;select name="mode"&gt;
  &lt;option selected="selected" value=""&gt;&lt;/option&gt;
  &lt;option value="1"&gt;the money withdraw&lt;/option&gt;
  &lt;option value="2"&gt;the money income&lt;/option&gt;
  &lt;/select&gt;
  &lt;input id ="entryDate" type="date" name="entryDate"&gt;
  &lt;input type="text" name="entryName"&gt;
  &lt;input type="text" name="entryValue"&gt;
  &lt;input type="submit" value="Enter"&gt;
  &lt;input type="reset" value="Clear"&gt;                    
  &lt;/form&gt;
  
  &lt;form name="getEntry" action="getEntry.php" method="post"&gt;
  Choose month and year for monthly overview:
  &lt;select name="month"&gt;
     &lt;option id = "selectedMonth" selected="selected" value=""&gt;&lt;/option&gt;
  
  &lt;/select&gt;
  &lt;select name="year"&gt;
  &lt;option id = "selectedYear" selected="selected" value=""&gt;&lt;/option&gt;
  &lt;/select&gt;
  &lt;input type="submit" value="Display"&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>I used simple javascript to automatically fill the form inputs "entryDate, selectedYear, selectedMonth" by actual date and some other dates used by the further scripts.</p>
  
  <p>My problem is, that when the site is loaded, only first input is automatically filled - the input with id = entryDate.</p>
  
  <p>The next 2 inputs are empty. But, when I press F5 and the site is reloaded again, the 2 inputs are filled correctly.</p>
  
  <p>Could you please help me fix it to have all 3 forms filled when the site is loaded for the first time...</p>
  
  <p>Thank you</p>