How to submit a form to multiple web sites?

  • Follow


How can I submit a form to multiple web sites when user click the
submit button? Something like the following:

myform.action = url_of_server1;
myform.submit();
myform.action = url_of_server2;
myform.submit();

The above code only submit form to url_of_server1. The second submit is
ignored. Is there any trick to make it works? For example is it
possible to use XMLHttpRequest object to submit the form
asynchronously?

0
Reply ningjun.wang (11) 12/20/2005 2:06:34 PM

As far as I'm aware - a client side form post can only submit to a single 
form, the result of that form could then post again, but you cannot post two 
simultaneously.

Another way to do this would perhaps be using frames with the two frames in 
their own frame...or an even better idea is to use IFrames for each form?

I'm sure the experts here will confirm or amend what I've said   ;o)

Cheers!

<ningjun.wang@lexisnexis.com> wrote in message 
news:1135087594.651903.142250@g44g2000cwa.googlegroups.com...
> How can I submit a form to multiple web sites when user click the
> submit button? Something like the following:
>
> myform.action = url_of_server1;
> myform.submit();
> myform.action = url_of_server2;
> myform.submit();
>
> The above code only submit form to url_of_server1. The second submit is
> ignored. Is there any trick to make it works? For example is it
> possible to use XMLHttpRequest object to submit the form
> asynchronously?
> 


0
Reply sh 12/20/2005 2:33:55 PM


It looks like what you're trying to do that has a better server side
solution.

It might be possible to get two submits.

Oh ... it's ugly.

I can think of it only because I've seen code where forms were getting
submitted twice unintentially.

Experiment with this...

<html>
<head>
<script>
function doSubmit() {
  myform.action="url_of_server1";
  myform.submit();
}
</script>
</head>
<body>
<form name="myform" action="url_of_server2" onsubmit="doSubmit();">
<input type="submit" value="Submit" name="Submit">
</form
</body>
</html>

0
Reply gimme_this_gimme_tha 12/20/2005 11:32:42 PM

ningjun.wang@lexisnexis.com wrote:
> How can I submit a form to multiple web sites when user click the
> submit button? Something like the following:
>
> myform.action = url_of_server1;
> myform.submit();
> myform.action = url_of_server2;
> myform.submit();

If you put an IFRAME into your page:
<IFRAME name=myframe1 src="about:blank"></IFRAME>

and then insert myform.target = "myframe1" before the first
myform.submit(), the response will be directed to the embedded iframe.
Subsequently to that submit, you'd better change back the
myform.target.  I could imagine that there might be an issue since the
second submit will wipe out the target of the first submit, but that
shouldn't affect what happens server side.  Experimental results will
be appreciated.

Csaba Gabor from Vienna

0
Reply Csaba 12/21/2005 1:31:42 AM

On 2005-12-20, ningjun.wang@lexisnexis.com <ningjun.wang@lexisnexis.com> wrote:
> How can I submit a form to multiple web sites when user click the
> submit button? Something like the following:
>
> myform.action = url_of_server1;
> myform.submit();
> myform.action = url_of_server2;
> myform.submit();
>
> The above code only submit form to url_of_server1. The second submit is
> ignored. Is there any trick to make it works? For example is it
> possible to use XMLHttpRequest object to submit the form
> asynchronously?

after the first submit succeds the page is cleared and the javascript stops
executing.

one way would be foe the CGI at server1 to use libcurl (etc) to submit the
data to server2 

another would be to clone the form in a popup and submit one to each server

a third would be to use xmlhttprequest etc.....

what sort of result are you looking for?

Bye.
   Jasen
0
Reply Jasen 12/21/2005 5:33:00 AM

Your suggestion works great. Here is my sample code:

<script language="JavaScript">
function submitForm(theform) {
	theform.action = "http://www.google.com/";
	theform.target="myframe1";
	theform.submit();

	theform.target="";
	theform.action = "http://www.yahoo.com/";
	theform.submit();

}
</script>

<html>
<body>
<form action="" onSubmit="submitForm(this); return false;">
<input type="text" name="userName" value="" />
<input type="Submit" />
</form>
<IFRAME name="myframe1" src="about:blank" width="0"
height="0"></IFRAME>
</body>
</html>

When you click the submit button, the form is POST to both Google and
Yahoo (I verified this by Network sniffer). In the end, you only get
the result page from the second submit (the Yahoo result page). This is
fine. I don't care the result page from the first submit.

Thanks for the help.

0
Reply ningjun 12/21/2005 4:14:00 PM

5 Replies
92 Views

(page loaded in 0.129 seconds)

Similiar Articles:













7/4/2012 8:33:05 AM


Reply: