Submitting a form to 2 different actions

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
ansa
Forum Commoner
Posts: 31
Joined: Tue Aug 29, 2006 1:58 am
Location: Hamburg, Germany

Submitting a form to 2 different actions

Post 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?
choppsta
Forum Contributor
Posts: 114
Joined: Thu Jul 03, 2003 11:11 am

Post 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.
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post 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 :(
ansa
Forum Commoner
Posts: 31
Joined: Tue Aug 29, 2006 1:58 am
Location: Hamburg, Germany

Post 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...
Post Reply