How can I have a page automatically click a form button after opening local html file

26,000

Try to submit on page load :

window.onload = function(){
  document.forms['FORM_NAME'].submit()

}

or you can also click button on page load , but submiting form might be better idea

Share:
26,000
Admin
Author by

Admin

Updated on October 16, 2020

Comments

  • Admin
    Admin over 3 years

    My site has a page where I can parse specific logs by filling out form fields and pressing a submit button.Sometimes I have to parse 100 different logs(which are automatically downloaded by my site from another FTP location) so I'm trying to make it as automated as possible. I have created a file on my local PC named log.html with this content

    <form action="MYSITEURL" method="POST" target="_blank" >
       <input type="password" name="password" value="MYPASSWORD"/>
       <input type="text" name="LogCommand" value="NAME-OF-THE-LOG-AND-LOCATION"/>
       <input type="submit" value="Submit1stLog" />
    </form>
    

    When I open the log.html file on my local PC, it opens with Firefox and I can see 2 fields which are automatically filled with password and some other info that I need about the log file names and commands, and I have a Submit button. When I manually press Submit, the local file connects to my website and sends those values and submits it.Basically I fill out the form locally instead of going to my website. This way I can have 100 lines like the above one within one local HTML file and press 100 submit buttons manually, instead of going to my site 100 times.

    My goal is to have some sort of JavaScript or something similar that will automatically click the Submit button for me as soon as I open the log.html local file.Is this possible? What if I have 100 Submit buttons?

    I tried to put the following in log.html but it didn't work

    <form action="MYSITEURL" method="POST" target="_blank" > <input type="password" name="password" value="MYPASSWORD"/> <input type="text" name="LogCommand" value="NAME-OF-THE-LOG-AND-LOCATION"/> <input type="submit" id="Submit1stLog" value="Submit1" /> </form>
    
    <script>
       function clickButton()
       {
          document.getElementById('Submit1stLog').click();
       }
    </script>
    

    If you noticed,I added the id="Submit1stLog" part and then tried to get element ID. This didn't work and I'm terrible at this if you noticed so any help is appreciated !

    Thank you.