milan
milan

Reputation: 2219

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>

Upvotes: 1

Views: 2325

Answers (3)

reign
reign

Reputation: 89

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>

Upvotes: -1

MK.
MK.

Reputation: 34517

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.

Upvotes: 2

tobyodavies
tobyodavies

Reputation: 28089

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

Upvotes: 2

Related Questions