SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form to automatically execute after the page is already loaded not at onload.

    I need a way other than "window.onload " to execute "myform.Submit1".

    As I have it now the Submit button executes "myform" correctly if you do it manually.

    I want "myform" to automatically execute after the page is already loaded not at onload.


    Code:
    <body>
    ...
    	<script type="text/javascript">
            window.onload = function () {
            	document.myform.Submit1.click();
            	self.location="http://mysite.com/webpage.php";
            }
        </script>
    </body>

  2. #2
    SitePoint Enthusiast -RT-'s Avatar
    Join Date
    May 2014
    Location
    London, United Kingdom
    Posts
    42
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I think you need to clarify what you mean. When do you want the form to be submitted?
    Immediately after the page has loaded without any user interaction?
    When a user clicks submit?

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want the form to be submitted directly after the page is loaded.
    I do not want any interaction with the page at all just a blip and back to the main page.
    As of now the page shows a lone Submit Button and "windows.onload" does nothing.
    If I select the Submit Button it executes the form perfectly.
    I want JavaScript to do it after the page is loaded.

  4. #4
    SitePoint Enthusiast -RT-'s Avatar
    Join Date
    May 2014
    Location
    London, United Kingdom
    Posts
    42
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Philosophaie View Post
    I want the form to be submitted directly after the page is loaded.
    I do not want any interaction with the page at all just a blip and back to the main page.
    As of now the page shows a lone Submit Button and "windows.onload" does nothing.
    If I select the Submit Button it executes the form perfectly.
    I want JavaScript to do it after the page is loaded.
    Changing .click() to .submit() should do the job. Are you sure JavaScript is the best place to do this for what you want? A user may have JavaScript disabled.

  5. #5
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,412
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    What is the purpose of the form (or the page) if you're immediately submitting an empty form? Are you looking for a way to do a redirect? If so, there are better ways to do this that don't rely on forms and JavaScript.
    "There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."

  6. #6
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am looking to redirect after the submit button is pressed.

    Automatically Submit button pressed then redirect.

    Nothing on the page is viewable all hidden boxes only thing viewable is the submit button.

  7. #7
    SitePoint Enthusiast -RT-'s Avatar
    Join Date
    May 2014
    Location
    London, United Kingdom
    Posts
    42
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Philosophaie View Post
    I am looking to redirect after the submit button is pressed.

    Automatically Submit button pressed then redirect.

    Nothing on the page is viewable all hidden boxes only thing viewable is the submit button.
    You're aware people can see the hidden stuff though right? So if you put anything sensitive there, they can see it. (right click, view source). And if JavaScript is disabled, they won't be redirected automatically.

  8. #8
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,412
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by Philosophaie View Post
    I am looking to redirect after the submit button is pressed.

    Automatically Submit button pressed then redirect.

    Nothing on the page is viewable all hidden boxes only thing viewable is the submit button.
    I understand what you're trying to do, but I'm interested in why you want to do it. If you're just redirecting the page as soon as it's loaded, why load the page at all? Are you showing a message to the user like "Thanks for logging in. You'll be redirected to page x now" or something?
    "There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."

  9. #9
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am using a javascript button to submit the main page form.

    I do php calculations in this current form and I want to automatically submit this form back to the main page.

    The whole thing is I want a button action with a form in my main page acting as if you never left the main page plus sending the data back.

  10. #10
    SitePoint Enthusiast -RT-'s Avatar
    Join Date
    May 2014
    Location
    London, United Kingdom
    Posts
    42
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Philosophaie View Post
    I am using a javascript button to submit the main page form.

    I do php calculations in this current form and I want to automatically submit this form back to the main page.

    The whole thing is I want a button action with a form in my main page acting as if you never left the main page plus sending the data back.
    Can't you just do those calculations when the user first requests the main page (and bypass the form altogether)? What information are you trying to get in order to do calculations?

  11. #11
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,412
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by Philosophaie View Post
    I am using a javascript button to submit the main page form.

    I do php calculations in this current form and I want to automatically submit this form back to the main page.

    The whole thing is I want a button action with a form in my main page acting as if you never left the main page plus sending the data back.
    OK, well have you thought about submitting the first form via AJAX? The target script could do the processing and return some data, and the user would never have to leave the first page.
    "There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •