0

I am using multiple form in a page here is my HTML code:

<form name="myform" id="myform" method="post" action="test.php">
<a href="javascript: submitform();" >submit</a>
<input type="hidden" name="encKey" value="12" />
</form>

<form name="myform" id="myform" method="post" action="test.php">
<a href="javascript: submitform();" >submit</a>
<input type="hidden" name="encKey" value="12" />
</form>


<form name="myform" id="myform" method="post" action="test.php">
<a href="javascript: submitform();" >submit</a>
<input type="hidden" name="encKey" value="12" />
</form>

And here is my javascript code:

<script type="text/javascript">
function submitform()
{
  document.myform.submit();
}
</script>

When i click on submit link, form is not submitting and gererate error in backend:

TypeError: document.myform.submit is not a function.

What may be issue?

Thanks

1
  • 1
    IDs and name attribute are meant to be unique.. forms are not attached to the document object directly. Commented Nov 22, 2013 at 8:49

5 Answers 5

1

I think you should use unique ids for all the forms. Then you can have a function that takes as a parameter the id of the form that you want to submit and then submit it. So you can have something like

<script type="text/javascript">
function submitform(formid)
{
  document.getElementById(formid).submit();
}
</script>

Sign up to request clarification or add additional context in comments.

Comments

0

You may try this

<script type="text/javascript">
function submitform()
{
  document.getElementById('myform').submit();
}
</script>

Comments

0

You can also use document.forms["myForm"].submit();. In this case "myForm" is the name of each form and it has to be unique as well as id.

Comments

0

First of all you've got 3 id which are the same (myform), an id has to be unique.

Comments

0

the id of a form must be unique, try to change the form id to only name.

you can try to use

document.getElementById('formId').submit()
to submit the information of a form.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.