Tabatha M Tabatha M - 18 days ago 9
Javascript Question

HTML button onload submit

I have a button example below

<button id="startrunning">go</button>


There is no form or anything I'm using on the same page java script to detect it's click. It will work like I want it to when I click it. I want to see when the page is loaded it will automatically submit it's self is there a way?

Thank you

Answer

jsFiddle: http://jsfiddle.net/QEu84/10/

<script type="text/javascript">
    function submit()
    {
        document.getElementById("startrunning").click(); // Simulates button click
        document.submitForm.submit(); // Submits the form without the button
    }
</script>

<body onload="submit()">
    <form id="submitForm">
        <button id="startrunning">go</button>
    </form>
</body>
Comments