Click to See Complete Forum and Search --> : Send FORM data to different scripts


Nedals
02-10-2003, 03:04 PM
10% of browsers disable javascript!
I would like to send form data to 2 different scripts depending on which button is clicked.
Here's is how I do it using javascript. How do I accomplish the same thing without using javascript? <script type="text/javascript">
<!--
function sendto(which) {
if (which == "A") { document.theform.action = "...cgi-bin/scriptA.cgi" }
else { document.theform.action = "...cgi-bin/scriptB.cgi" }
document.theform.submit()
}
//-->
</script>
....

....
<form name="theform" action="" method="post">
<input name="elementA" type="text">
<input name="elementB" type="text">
<input type="button" value="Submit to scriptA" onClick="sendto('A')">
<input type="button" value="Submit to scriptB" onClick="sendto('B')">
</form>
....

Charles
02-10-2003, 03:12 PM
Without JavaScript you will have to send to a third CGI script that forwards the form as required.

<form name="theform" action="cgi-bin/pipe.pl" method="post">
<div>
<input name="elementA" type="text">
<input name="elementB" type="text">
</div>
<div>
<input type="submit" value="Submit to scriptA" onclick="document.theform.action='cgi-bin/scriptA.cgi'">
<input type="submit" value="Submit to scriptB" onclick="document.theform.action='cgi-bin/scriptB.cgi'">
</div>
</form>

Nedals
02-10-2003, 04:49 PM
Charles, I'm a little confused.

<input type="submit" value="Submit to scriptA" onclick="document.theform.action='cgi-bin/scriptA.cgi'">

This line still contains javascript, does it not? And, leaving it in will not require the 3rd script. On the assumption that the onClick section should be ommitted, do you happen to know how I get the form data to scriptA or scriptB via your suggested pipe.pl?

Charles
02-10-2003, 05:27 PM
Yes, the form goes to pipe.pl when there is no JavaScript. What that script will look like will depend upon what language you are using, but that's not anything that I've ever done before. I would suggest that you complete the form and then post the HTML and both scripts that you have over at the CGI forum.