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:
<form action="product.php" method="get" name="frmProduct" id="frmProduct" enctype="multipart/form-data">
<input onclick="submitAction()" id="submit_value" type="button" name="submit_value" value="">
</form>
<script type="text/javascript">
function submitAction()
{
document.frmProduct.submit();
}
</script>
I also tried this:
<script type="text/javascript">
function submitAction()
{
document.forms["frmProduct"].submit();
}
</script>
Both show me the same error :(
Make sure that there is no another form with the same name and make sure that there is no name="submit" or id="submit" in the form.
I had the same issue when i was creating a MVC application using with master pages. Tried looking for element with 'submit' as names as mentioned above but it wasn't the case.
For my case it created multiple tags on my page so there were some issues referencing the correct form.
To work around this i'll let the button handle which form object to use:
and with the js:
What I used is
Just because everything else didn´t work.
means that you named your submit button or some other element
submit
. Rename the button tobtnSubmit
and your call will magically work.When you name the button submit, you override the
submit()
function on the form.Possible solutions -
1.Make sure that you don't have any other element with name/id as submit.
2.Try to call the function as
onClick = "return submitAction();"
3.
document.getElementById("form-name").submit();
You can try
Don't you have more than one form with the same name ?