简体   繁体   中英

Javascript Auto Form submission not working

I have following simple HTML Form & i tried to submit the form automatically during page load. Below Javascript code is not automatically submitting the form.

HTML :

<form action="SSL.php" method="POST" name="TForm" id="transactionForm">
<input type="hidden" name="merchantTxnId" id="merchantTxnId" value="test">
<input type="submit" name="submit" id="submit" value="submit" style="visibility:hidden">
</form>
Redirecting ... Please wait...

Java script:

<script>
    window.onload = function(){
        alert(1); // this is working..
            document.getElementById("transactionForm").submit(); //nothing is happening with this line . form is not getting submitted
    }
</script>

I found following error in Chrome console mode says: 在此处输入图片说明 Kindly suggest me where the problem is...

You may not use submit as the name or id of any of your form elements.

The reason is, that you can reach each child of your form via document.getElementById('form').nameOfTheChild where nameOfTheChild is the name of the child. If you have a child with the name submit , document.getElementById('form').submit is a shortcut to address that child.

The documentation of .submit() says that :

Forms and their child elements should not use input names or ids that conflict with properties of a form, such as submit, length, or method. Name conflicts can cause confusing failures.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM