I am trying to make a link submit a form. How come when I name a submit input element submit, the link no longer works?
//breaks form submission
<input type="submit" value="Submit" name="submit" />
//does not break form submission
<input type="submit" value="Submit" name="xsubmit" />
In Chrome I receive the following error.
Uncaught TypeError: Property 'submit' of object #<HTMLFormElement> is not a function
NOT Working
<p>Type 'correct' to validate.</p>
<form method="post" enctype="multipart/form-data">
<input type="submit" value="Submit" name="submit" />
<a id="btn_submit">
<span id="txt_submit">Submit</span>
</a>
</form>
<script>
$("#btn_submit").click(function() {
$("form").submit();
});
$("form").submit(function() {
});
</script>
WORKING
<p>Type 'correct' to validate.</p>
<form method="post" enctype="multipart/form-data">
<input type="submit" value="Submit" name="xsubmit" />
<a id="btn_submit">
<span id="txt_submit">Submit</span>
</a>
</form>
<script>
$("#btn_submit").click(function() {
$("form").submit();
});
$("form").submit(function() {
});
</script>
“Submit” is a reserved word. It conflicts with javascript. Just change the name of the input to something else.
From the jQuery documentation on the method submit():