简体   繁体   中英

Why doesn't my form submit automatically?

I don't see what is wrong, does submit() not work anymore?

<html>
<head>
    <title>This is the title</title>
    <script type = "text/javascript">

        function onLoad() {
            document.getElementById("input1").value="text1";
            document.getElementById("input2").value="text2";
            document.getElementById('form').submit();
        }

    </script>
</head>
<body onload="onLoad();">
<form method="post" name="form" id="form" action="test.txt">
    <label for="input1">Input1</label> <input id="input1" name="input1" type="text"/>
    <label for="input2">Input2</label> <input id="input2" name="input2" type="text"/>
    <input name="submit" id="submit" value="submit" type="submit"/>
</form>
</body>
</html>

这将工作,如果你没有name编你的提交按钮submit该则会覆盖方法定义

Your problem is that the button is named submit and hs id submit. Change that and it works. You overwrote submit function with a submit button element.

try this one..

<html>
<head>
    <title>This is the title</title>
    <script type = "text/javascript">
        function Test() {
            document.getElementById("input1").value="NewValue1";
            document.getElementById("input2").value="NewValue2";
            document.getElementById('form').submit();
        }

    </script>
</head>
<body onload="Test();">
<form method="post" name="form" id="form" action="new.html">
    <label for="input1">Input1</label> <input id="input1" name="input1" type="text"/>
    <label for="input2">Input2</label> <input id="input2" name="input2" type="text"/>
    <input name="submit" id="submit" value="submit" type="submit"/>
</form>
</body>
</html>

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