Submitting automatically a form with JavaScript

Asked By 0 points N/A Posted on -
qa-featured

Hello,

I want to create a page (HTML/PHP) that loads an URL, in this URL there are a submit button that doesn't have a name but have an id ("u721957_1"). I want that when I load this page, automatically this submit button is pushed. I don't like to submit the form directly because there are some data in the button that I need, I tried this: document.getElementById('u721957_3').click() as a function in the onLoad of the body but it doesn't work (you have to note that I can't change the id of the button).

Any solution please??

SHARE
Best Answer by Collins Brady
Answered By 0 points N/A #97063

Submitting automatically a form with JavaScript

qa-featured

You must change this code as:

document.getElementsByTagName('form')[0].submit();
Go ahead and change it.

 But I have a better Idea for you. In this code specifying instruction about to onload function. You can use this code.

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

It will work for this function and automatically submit form when load into browser window. In this code you can also insert an option of frequently submit this form many times with defined intervals. You no need to insert your ID here because it based on single submission and will automatically pick your desire button to submit.

Best Answer
Best Answer
Answered By 0 points N/A #97065

Submitting automatically a form with JavaScript

qa-featured

Greetings,

This may be out of your question, but you really don't need a button to put the data on the URL if you just want the button to be pressed automatically. You just need to put on the type attribute nothing.

But since you asked, I'll just answer the question.

Putting “onload” on the body tag always works. If it doesn't work, the main cause of the problem is in your JavaScript codes. The JavaScript codes may be tangled or they don't do what they are supposed to do. You have to do a lot of testing. Try putting the JavaScript on other tag or use other command listeners and never be afraid to use the alert method. Using the alert method is a really good practice in testing your command listeners to see if they work.

If you are frustrated because it still doesn't work and too lazy to trace the problem, just use jQuery instead of JavaScript. Of course you have to download the jQuery.

Regards.

Login/Register to Answer

Related Questions