This method does not work (

<script> function testID(id, type){ document.getElementById('beforepay').submit(); } </script> <form accept-charset="windows-1251" target="_blank" id="beforepay" name="beforepay" method="post" action="" onSubmit="testID(322332, 1);return false;"> <input autocomplete="OFF" style="color: rgb(0, 0, 0);" name="submit" value="Далее" type="submit"> </form> 

In the console writes:

document.getElementById("beforepay").submit is not a function

What's my mistake? Moreover, I noticed that it does not work when submit in handleresponse

  • Maybe you have another item with the same ID? For example, a button. Check it out. - angry
  • If it weren’t, it wouldn’t work forever, otherwise it would work: <br> <code> xmlHttp.onreadystatechange = document.getElementById ("beforepay"). Submit (); </ code> <br> And so no: < br> <code> xmlHttp.onreadystatechange = function () {document.getElementById ("beforepay"). submit (); } </ code> <br> I can not understand for what reason ( - iproger
  • Try to access the form as forms ['beforepay']. submit (); - uramer239
  • Writes <b> forms is not defined </ b> - iproger

1 answer 1

Everything is much simpler here - the problem is in your code, namely in

 <input autocomplete="OFF" style="color: rgb(0, 0, 0);" name="submit" value="Далее" type="submit"> 

Now I will explain - in javascript'e the form values ​​are parsed by the name attribute, after that we can have access to them. Those. in our case, the document.beforepay.submit function is overwritten by the value of your input, which is why submit is not a function , because in this case submit is input ...
In general, to solve this problem, simply change the name attribute for your input to anything but not submit :)

By the way, purely for yourself - make an alert(document.beforepay.submit) and you will see that this is html input

  • Thanks, it helped. I just did not write the form myself, but copied) Hence the nonsense of the type autocomplete = "OFF" on the button) name = submit was not noticed because of the large number of attributes) Thank you) But a problem arose: when the form is sent via js then browsers block it as a popup window, because target = _blank. How can I avoid this? Or remove _blank only? - iproger
  • About the problem: .... and where is the problem then? ^^ - Zowie
  • Clear, thanks) - iproger