开发者

Why doesn't my form submit automatically?

开发者 https://www.devze.com 2023-01-24 06:38 出处:网络
I don\'t see what is wrong, does submit() not work anymore? <html> <head> <title>This is the title</title>

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="inpu开发者_运维技巧t2" name="input2" type="text"/>
    <input name="submit" id="submit" value="submit" type="submit"/>
</form>
</body>
</html>


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.


This would work if you hadn't nameed your submit button submit this clobbers the method definition


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消