user2684795
user2684795

Reputation: 5

Nothing happens with JavaScript form submission

Can anybody tell me Why I click on button to submit form -> it works, but when I use javascript to auto submit -> it failed ?

I have this form on aaa.com, it submit to bbb.com/result.jsp (another domain)

<form id="myForm" name="myForm " method="post" action="www.bbb.com/result.jsp">
<input name="var01" value="var01 ">
<input name="var02" value="var02 ">
 <input type="submit" name="searchButton" value="Search">
</form>

Manually click on Search button, result.jsp works fine.

When I added following script, result.jsp page doesn’t work

<script>
document.getElementById("myForm").submit();
</script>

Upvotes: 0

Views: 886

Answers (2)

Enkk
Enkk

Reputation: 376

As I remember, the HTML id attribute is case-sensitive. You are calling the .submit() method on myform while your form id is myForm.

Upvotes: 2

Quentin
Quentin

Reputation: 943108

Your form has id="myForm" but your JavaScript is looking for myform. IDs are case-sensitive.

Changing that makes it work.

Upvotes: 3

Related Questions