Can anyone tell me what is going wrong with this code? I tried to submit a form with JavaScript, but an error “.submit is not a function” shown. See below for more details of the code:
JavaScript
x
13
13
1
<form action="product.php" method="get" name="frmProduct" id="frmProduct" enctype="multipart/form-data">
2
3
<input onclick="submitAction()" id="submit_value" type="button" name="submit_value" value="">
4
5
</form>
6
7
<script type="text/javascript">
8
function submitAction()
9
{
10
document.frmProduct.submit();
11
}
12
</script>
13
I also tried this:
JavaScript
1
7
1
<script type="text/javascript">
2
function submitAction()
3
{
4
document.forms["frmProduct"].submit();
5
}
6
</script>
7
Both show me the same error 🙁
Advertisement
Answer
submit is not a function
means that you named your submit button or some other element submit
. Rename the button to btnSubmit
and your call will magically work.
When you name the button submit, you override the submit()
function on the form.