Is there a way to submit an HTML form using JavaScript that is guaranteed to work in all situations?
I elaborate. The common approach seems to be:
fo
Create another form in JavaScript, and apply its submit()
method on your original form:
<html>
<script>
function hack() {
var form = document.createElement("form");
var myForm = document.example;
form.submit.apply(myForm);
}
</script>
<form name="example" id="example" method="get" action="">
<input type="hidden" value="43" name="hid">
<button
type="button"
name="submit"
onclick="hack();return false;"
>Submit</button>
</form>
</html>
form.submit
is the reference to a fresh and clean submit method, and then you use apply(myForm)
to execute it with the original form.