By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,480 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,480 IT Pros & Developers. It's quick & easy.

How to submit a form to multiple web sites?

P: n/a
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?

Dec 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
@sh
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!

<ni**********@lexisnexis.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.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?

Dec 20 '05 #2

P: n/a
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>

Dec 20 '05 #3

P: n/a
ni**********@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

Dec 21 '05 #4

P: n/a
On 2005-12-20, ni**********@lexisnexis.com <ni**********@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
Dec 21 '05 #5

P: n/a
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.

Dec 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.