title: Automatically submit a form
body: <p>I am trying to get a form to submit automatically, which feeds a username and password to another form.</p>
  
  <p>If I remove the javascript and just have the form display on the screen, and manually click the Submit button, the result is I get automatically logged in on the resulting page. This is the result I want.</p>
  
  <p>If I leave the javascript in place, it actually doesn't automatically log me in but it does pass across the username and password pre-filled on the resulting page, then I have to click Submit on the resulting page.</p>
  
  <p>How can I make it automatically submit the form to work the same way as a user actually hitting the submit button? Also I understand that this may not be the most secure way to pass a username and password across, but this is for a special use case.</p>
  
  <p>Note: MyForm is a php page, and I am submitting to an aspx page.</p>
  
  <p>Here is code of what my form would look like:</p>
  
  <pre><code>&lt;form id='myForm' method='post' action='https://blah.com/Login.aspx'&gt;";
  &lt;p&gt;Username: &lt;input value='usernameHere' name='Username' type='text' id='Username' data-index='0' maxlength='255' placeholder='Username' class='loginUsername' /&gt;";
  &lt;p&gt;Password: &lt;input value='passwordHere' name='Password' type='password' id='Password' placeholder='Password' /&gt;";
  &lt;p&gt;&lt;input type='submit' name='btnSignIn' value='Sign In' id='btnSignIn' /&gt;
  &lt;/form&gt;
  &lt;script type="text/javascript"&gt;
      document.getElementById('myForm').submit();
  &lt;/script&gt;
  </code></pre>
  
  <p>Thank you.</p>