How to submit a form to multiple web sites?

N

ningjun.wang

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?
 
@

@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!
 
G

gimme_this_gimme_that

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>
 
C

Csaba Gabor

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
 
N

ningjun.wang

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,096
Latest member
ThurmanCre

Latest Threads

Top