-1

I have a form without any ID.

<form action="LoginServlet" method="post" onsubmit="return checkForm(this);">

How can I get the form to submit?

I only have on form on that page, so I tried this but it didn;t work.

document.forms[0].submit()
Nitesh
  • 1,564
  • 2
  • 26
  • 53
  • _“Didn’t work”_ isn’t a problem description. Any errors in the console? – Sebastian Simon Feb 04 '18 at 07:26
  • more code?i test worked – xianshenglu Feb 04 '18 at 07:26
  • Use the [browser console (dev tools)](https://webmasters.stackexchange.com/q/8525) (hit `F12`) and read any errors. You have an `` with `name="submit"`. [If you don’t rename that button, you can’t use the `submit` function.](https://stackoverflow.com/questions/6525790/javascript-submit-is-not-a-function) – Sebastian Simon Feb 04 '18 at 07:44
  • @nitesh if you try to submit the form, it won't work since it has captcha. Submitting programmatically will be difficult since it has captcha. – parag Feb 04 '18 at 07:47
  • @parag I have entered the captcha directly first. I then need to perform the "Login" action. document.getElementById('captcha').value = '\(value)'; – Nitesh Feb 04 '18 at 07:49

2 Answers2

2

try this,tested ok according to the url you give:

document.getElementsByClassName('btn btn-primary')[0].click();

code below doesn't work because the website have an input whose name is 'submit'

document.forms[0].submit()

so ,when you execute

document.forms[0].submit//returns an input element,not a function

so,

document.forms[0].submit() //doesn't work,cause document.forms[0].submit is not a function
xianshenglu
  • 4,943
  • 3
  • 17
  • 34
  • 'document.getElementsByClassName('btn btn-primary')[0].click();' This didn't work too. – Nitesh Feb 04 '18 at 07:47
  • @Nitesh ,this url:passbook.epfindia.gov.in/MemberPassBook/Login.jsp ?i test worked – xianshenglu Feb 04 '18 at 07:52
  • Sorry, It works. Problem now is with the pass text which I set it this way 'document.getElementById('password').value = 'passwordhere';' Can you help me with this? I'm getting error Password not available if I set it by this. – Nitesh Feb 04 '18 at 08:05
  • @Nitesh you set it right,and i test it right,what is the problem? – xianshenglu Feb 04 '18 at 08:10
  • Sorry, it was just typo in my code. Thanks for help! :) – Nitesh Feb 04 '18 at 08:14
1

Try this:

document.getElementsByTagName('form')[0].submit();
dhna
  • 71
  • 2
  • 10
  • 2
    Your answer could be improved by adding more information on what the code does and how it helps the OP. – Tyler2P Jun 03 '22 at 17:57