开发者

Did button actually click?

开发者 https://www.devze.com 2022-12-13 12:56 出处:网络
I have some javascript that ends up programatically clicking on a button: document.getElementById(\"myButton\").click();

I have some javascript that ends up programatically clicking on a button:

  document.getElementById("myButton").click();

This in turn results in the form being submitted using a function call:

  <form onsubmit="submit_this_form(this);return false;" action="" method="POST">

It seems that a good percentage of the time either the actual button click is not going through or the form is not being submitted. I think the button click is going through and I know the code is being called because I have a counter embedded and I can see it is executing.

My question is...is there an event or a way to verify that the form actually posted? By the way, I don't开发者_JS百科 have control of the HTML code so I can't change the tag content.


<form onsubmit="submit_this_form(this);return false;" action="" method="POST">

return false after submit_this_form() essentially stops the form from actually submitting. I believe if you change it to:

<form onsubmit="submit_this_form(this);" action="" method="POST">

It should work as you want.

Using return false after an event handler will essentially 'hijack' the default functionality. Basically, whatever your event handler function script does replaces the default behavior, which in this case, is submitting the form data to the server.


I don't think you can verify that form is actually where submitted. But you can submit it by hand via XMLHTTPRequest and check for server responce. This way you will be sure thet form is submitted. And you can have an event (your custom event) that says about form submission if you need to... BTW do not forget to prevent forms default submit if you go AJAX way.

Check jquery.form plugin to make a fast rollout of AJAX form submission and look is it what you want or not.
Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消