Page 1 of 1

Submitting a form to 2 different actions

Posted: Wed Oct 25, 2006 3:22 am
by ansa
Hi

I have the following code. This code is to submit a form to two different actions. First action is a script in Page1.php, another is a script in Page2.php.

Code: Select all

<script language=javascript> 
function doSubmit() {
document.Form1.action = "Page1.php";
document.Form1.submit(); // Submit the page 
document.Form1.action = "Page2.php"; 
document.Form1.submit(); 
return true; 
</script>
I thought it would work, but somehow it runs only the Page1 script. When I comment out the action and submit of Page1.php, then it runs the Page2.

Why is it? Is there a better solution to run 2 different actions (2 different php scripts) in 1 form?

Posted: Wed Oct 25, 2006 5:43 am
by choppsta
You can achieve this using Ajax techniques. There are a number of different techniques you can use depending on your target audience.
look up the XMLHttpRequest object or perhaps the Iframe Call.

Posted: Wed Oct 25, 2006 5:46 am
by kaszu

Code: Select all

document.Form1.submit();
sends a form and nothing after that won't be executed, because browser requests "page1.php" (sends form data to it and receives something else to display).

As i understand all you need to do is to send data to these pages, what you can do is use Ajax
or use ...submit() and include "page2.php" from "page1.php".

Sorry my english is poor.

EDIT: too late :(

Posted: Wed Oct 25, 2006 10:24 am
by ansa
I haven't done anything with Ajax, although i heard there's nothing new with this technique. I thought I could do this 2 actions from a simple php or javascript command...