title: Populate hidden field with autocomplete value
body: <p>I have an HTML form with a regular text input and a hidden field.</p>
  
  <p>I also have the following code that will populate the hidden field with the value of the text field either when it is changed, or if the text field has a default value (supplied by the page itself):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function() {
    var emailinput = document.getElementById('emailval');
  
    document.getElementById('usernameval').value = emailinput.value;
  
    emailinput.onkeyup = function() {
      document.getElementById('usernameval').value = emailinput.value;
    }
  
    emailinput.onblur = function() {
      document.getElementById('usernameval').value = emailinput.value;
    }
  
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;input type="text" name="email" id="emailval" /&gt;
  &lt;input type="hidden" name="username" id="usernameval" /&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>This works well, except in the case where the browser autofills the text field.  If the user submits the form without changing the textfield.</p>
  
  <p>So my question is, is there any way to have the javascript pull the value from the browser-autofilled text field?</p>