How to submit a form when page loads using javascript?

I know this question has been answered many times but in my case the JavaScript code creates a infinite loop which makes my page load continuously,


    window.onload = function(){
        document.getElementById('theForm').submit();
    }

I also tried the below one and it doesn’t work.

<body onload="document.theform.submit()";>

The below code does what I need but it’s not perfect.


    window.onload = function(){
        document.getElementById('submit_button').click();
        setTimeout(function(){window.stop();},2500);
    }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s