How to fill in form field, and submit, using javascript?

后端 未结 5 1640
渐次进展
渐次进展 2020-11-29 23:34

If I have an html document whose rough structure is





相关标签:
5条回答
  • 2020-11-30 00:20

    You can try something like this:

        <script type="text/javascript">
            function simulateLogin(userName)
            {
                var userNameField = document.getElementById("username");
                userNameField.value = userName;
                var goButton = document.getElementById("go");
                goButton.click();
            }
    
            simulateLogin("testUser");
    </script>
    
    0 讨论(0)
  • 2020-11-30 00:23
    document.getElementById('username').value = 'foo';
    document.getElementById('login_form').submit();
    
    0 讨论(0)
  • 2020-11-30 00:31
    document.getElementById('username').value="moo"
    document.forms[0].submit()
    
    0 讨论(0)
  • 2020-11-30 00:32

    It would be something like:

    document.getElementById("username").value="Username";
    document.forms[0].submit()
    

    Or similar edit: you guys are too fast ;)

    0 讨论(0)
  • 2020-11-30 00:38

    This method helped me doing this task

    document.forms['YourFormNameHere'].elements['NameofFormField'].value = "YourValue"
    document.forms['YourFormNameHere'].submit();
    
    0 讨论(0)
提交回复
热议问题