Clicking submit button of an HTML form by a Javascript code

后端 未结 3 1843
野趣味
野趣味 2021-02-07 04:33

I don\'t know much about WEB probramming, so feel free to ask if I\'m missing any details.

There is a certain website which I\'m visiting very frequently, and it require

相关标签:
3条回答
  • 2021-02-07 05:10

    You can do :

    document.forms["loginForm"].submit()
    

    But this won't call the onclick action of your button, so you will need to call it by hand.

    Be aware that you must use the name of your form and not the id to access it.

    0 讨论(0)
  • 2021-02-07 05:24

    The usual way to submit a form in general is to call submit() on the form itself, as described in krtek's answer.

    However, if you need to actually click a submit button for some reason (your code depends on the submit button's name/value being posted or something), you can click on the submit button itself like this:

    document.getElementById('loginSubmit').click();
    
    0 讨论(0)
  • 2021-02-07 05:31
    document.getElementById('loginSubmit').submit();
    

    or, use the same code as the onclick handler:

    changeAction('submitInput','loginForm');
    document.forms['loginForm'].submit();
    

    (Though that onclick handler is kind of stupidly-written: document.forms['loginForm'] could be replaced with this.)

    0 讨论(0)
提交回复
热议问题