Results 1 to 7 of 7

Thread: Auto-submitting a form with javascript

  1. #1
    Old school, like an old fool. Flying Mullet's Avatar
    Join Date
    Apr 2003
    Location
    Napping in a peach tree.
    Posts
    19,185
    Articles
    6
    Blog Entries
    7
    Contributions
    • Former Administrator
    • Former Cid's Knight
    • Former Senior Site Staff

    Default Auto-submitting a form with javascript in Firefox

    Okay, so I'm playing around with some php and after the user inputs some data into a form I'd like to submit it to a php file to do the database work and then jave some javascript auto-submit an auto-populated form to take the user onto a results page.

    So here's what my source code looks like:

    <i>
    &lt;html>
    &lt;?php
    // database work
    ?>
    &lt;form name="createcharacterform" action="TorrentMain.php" METHOD="post">
    &lt;input type="hidden" NAME="playername" maxlength="20" value="&lt;?php print $playername; ?>"/>
    &lt;/form>
    &lt;script language="JavaScript">
    &lt;!-- hide this stuff from other browsers
    createcharacterform.submit();
    &lt;/script>
    &lt;/html>
    </i>

    Now, this works in IE, but being the responsible web developer that I am, I'm trying to also get it to work in Firefox at the moment. I've tried different variations of referencing the form including "document" an "window.document".

    Also, is there any way to have php automatically submit that form for me?

    And lastly, I would like to create individual php files to do my work rather than one master php file that submits to itself to help make the source code for managable if I can.
    Figaro Castle

  2. #2
    Last Exile Baloki's Avatar
    Join Date
    Sep 2003
    Location
    Dreaming a dream~
    Posts
    8,425
    Articles
    5
    Blog Entries
    2

    FFXIV Character

    Baloki Kyuu (Sargatanas)
    Contributions
    • Former Senior Site Staff
    FOA

  3. #3
    ORANGE Dr Unne's Avatar
    Join Date
    Dec 1999
    Posts
    7,394
    Articles
    1
    Contributions
    • Former Administrator
    • Former Developer
    • Former Tech Admin

    Default

    I'm still trying to figure out what you want to do. I don't see why you need to submit the form using Javascript at all. I don't understand why you'd be auto-submitting a form at all really; you can't submit the form until the user has input the data, and if you already have the data to begin with and don't need user input, you shouldn't even bother using forms; just pass the data directly to the PHP files in some way.

    Could you have a form, and when they click Submit, do whatever you need to in PHP, and then output the results in plain old HTML? If you want to display the results in a form, you can do that with HTML; set a value for all the form elements bases upon the results from the database stuff. You don't need to re-submit the form, which is what it appears you're doing.

    So far as the PHP files, you can use the PHP "include" or "require" statements to include and evaluate other PHP files from the current file.

  4. #4
    Old school, like an old fool. Flying Mullet's Avatar
    Join Date
    Apr 2003
    Location
    Napping in a peach tree.
    Posts
    19,185
    Articles
    6
    Blog Entries
    7
    Contributions
    • Former Administrator
    • Former Cid's Knight
    • Former Senior Site Staff

    Default

    Never mind. I didn't ask for help to have people critique my design. The only reason I posted was to find out how you auto-submit a form in Firefox, as I can get it to work in IE but not Firefox. It doesn't matter why I want to, I just want to know.

    Also, my results page is navigated to from several different areas, and I can't have the one html destination page handle all of these different calls to get here, so I need different php files, or one php file with methods, to handle the different navigation methods and then take the user to the common page. That's why I want to figure out how to get these different php files or one common php file call the common html page.
    Last edited by Flying Mullet; 01-08-2005 at 10:14 PM.
    Figaro Castle

  5. #5
    Last Exile Baloki's Avatar
    Join Date
    Sep 2003
    Location
    Dreaming a dream~
    Posts
    8,425
    Articles
    5
    Blog Entries
    2

    FFXIV Character

    Baloki Kyuu (Sargatanas)
    Contributions
    • Former Senior Site Staff

    Default

    I gave you W3schools so you could look up the alternatives to the current command your using, duh
    FOA

  6. #6
    Old school, like an old fool. Flying Mullet's Avatar
    Join Date
    Apr 2003
    Location
    Napping in a peach tree.
    Posts
    19,185
    Articles
    6
    Blog Entries
    7
    Contributions
    • Former Administrator
    • Former Cid's Knight
    • Former Senior Site Staff

    Default

    I was replying to Unne, duh.
    Figaro Castle

  7. #7
    Last Exile Baloki's Avatar
    Join Date
    Sep 2003
    Location
    Dreaming a dream~
    Posts
    8,425
    Articles
    5
    Blog Entries
    2

    FFXIV Character

    Baloki Kyuu (Sargatanas)
    Contributions
    • Former Senior Site Staff

    Default

    I knew, duh
    FOA

Posting Permissions

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