Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form submit with javascript works in Google Chrome only once

I have simple form.

<form target="_blank" action="somescript.php" method="Post" id="simpleForm">
<input type="hidden" name="url" value="http://...">
<input type="hidden" name="code" value="wrxosf">
</form>

...and there are some anchor link

<a href="#" onclick="$('#simpleForm').submit();return false;">Do it!</a>

It works fine in FireFox or IE, but Google Chrome. Chrome does once, then link become unclickable.

like image 564
Andrew Rumm Avatar asked Oct 26 '09 08:10

Andrew Rumm


People also ask

How do you submit form only once after multiple clicking on submit?

onsubmit = function () { if (allowSubmit) allowSubmit = false; else return false; } })(); (well, as sure-fire as you can get with JS enabled anyway). You could disabled the button as a visual confirmation to the end user that the form can only be submit once too. Very correct.


2 Answers

Also had such problem.

The decision was to add something random to URL each time before submitting.

HTML:

<form action="go.php" method="post" target="_blank" id="go">
...
</form>

JavaScript (jQuery):

$('#go').attr('action','go.php?'+Math.random()*1000).submit();
like image 166
Ilya Avatar answered Oct 19 '22 15:10

Ilya


Forms with target="_blank" submiting only once. This is webkit & chromium bugs.

like image 45
Andrew Rumm Avatar answered Oct 19 '22 15:10

Andrew Rumm