/    Sign up×
Community /Pin to ProfileBookmark

Send FORM data to different scripts

[i]10% of browsers disable javascript![/i]
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?

[code]<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>
….[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@CharlesFeb 10.2003 — [font=georgia]Without JavaScript you will have to send to a third CGI script that forwards the form as required. [/font]

[font=monospace]

<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>[/font]
Copy linkTweet thisAlerts:
@NedalsauthorFeb 10.2003 — 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?
Copy linkTweet thisAlerts:
@CharlesFeb 10.2003 — [font=georgia]Yes, the form goes to [font=monospace]pipe.pl[/font] 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.[/font]
×

Success!

Help @Nedals spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...