PDA

View Full Version : Auto-submitting a form with javascript



Flying Mullet
01-08-2005, 02:34 AM
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.

Baloki
01-08-2005, 05:42 PM
http://www.w3schools.com

Dr Unne
01-08-2005, 06:10 PM
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.

Flying Mullet
01-08-2005, 10:09 PM
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.

Baloki
01-08-2005, 10:21 PM
I gave you W3schools so you could look up the alternatives to the current command your using, duh

Flying Mullet
01-08-2005, 10:52 PM
I was replying to Unne, duh. :p

Baloki
01-08-2005, 11:07 PM
I knew, duh :p