How do I prevent the form from being submitted in front of the DOM?
4 answers
Just check before submission only to prevent posting before the House is ready.
<form method="POST" onsubmit="return handle()">
<input type="submit" />
</form>
<script>
function handle()
{
return imReady;
}
var imReady = false;
function setReady()
{
imReady = true;
}
// edit: add this line
window.onDomReady = setReady();
</script>
+1
source to share
Use jQuery to create submit button on DOM load
$(document).ready(function() {
$("form").append("<input type='submit' name='submit' value='submit'>");
}
However, this will create a javascript dependency for your application.
Or another option is to put the following code
<form action="post.php" method="post" onsubmit="return false">
0
source to share
Check out this blog post for how to check for DOM readiness. Then create a function that returns true when the DOM is ready and use this function inside your form tag:
<form onsubmit="return my_DOM_ready_function()">
0
source to share