/    Sign up×
Community /Pin to ProfileBookmark

Two actions in one form

Hi,

Please help. I confess I’m no Java expert.
I have a form. When the user clicks submit I would like form to be sent to two different cgi scripts.

Please help and don’t forget to make it simple. ?

Many thanks
Lyle

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@KorDec 29.2005 — You may use trick. Try this:

First add on your page two "hidden" iframes where you may submit.
[code=php]
<div style="visibility:hidden">
<iframe name="ifr1" width="20" height="20"></iframe>
<iframe name="ifr2" width="20" height="20"></iframe>
</div>
[/code]

Now you can build a function
[code=php]
<script type="text/javascript">
function submitTwice(f){
f.action = 'first.php';
f.target='ifr1';
f.submit();
f.action = 'second.php';
f.target='ifr2';
f.submit();
}
</script>
[/code]

and the form:
[code=php]
<form method="post">
....
<input type="button" value="Send" onclick="submitTwice(this.form)">
</form>
[/code]
Copy linkTweet thisAlerts:
@wpdfranMay 11.2007 — This is an AWESOME script. I know nothing about Javascript and was still able to use it. I have a question though. Is it possible to add a verification script to this? The script I need to use requires the form to have a name and I can't seem to figure out where to put it. Any ideas?
Copy linkTweet thisAlerts:
@ogunisikMar 22.2008 — thanks mate. this is realy working.
Copy linkTweet thisAlerts:
@kthurstoJul 07.2008 — Has anyone encountered any problems w/ this scipt working in Firefox? It works wonderfully for me in IE; but, does not submit any data via FF.
Copy linkTweet thisAlerts:
@tifotifoJul 31.2008 — i've tried this ....

link 1 works when [I]"f.target='ifr*';"[/I] is included and link 2 works when it is deleted. They don't both work together.

anyone?
Copy linkTweet thisAlerts:
@mustu9980Apr 01.2010 — That really worked and yes it worked in Firefox.

Now, after submitting i had a thankyou page which comes. Here after putting the first code in the thankyou page that is this:

"<div style="visibility:hidden">

<iframe name="ifr1" width="20" height="20"></iframe>

<iframe name="ifr2" width="20" height="20"></iframe>

</div>"

As my thankyou page was itself integrated in my action script when i submitted i got two thank you pages in new window which i dont want, infact i want the thankyou page to be opened in the same window, so i simply deleted f.target from the javascript, so now

Instead of this:

<script type="text/javascript">

function submitTwice(f){

f.action = 'first.php';

f.target='ifr1';

f.submit();

f.action = 'second.php';

f.target='ifr2';

f.submit();

}

</script>

i kept in the header of the contact for this:

<script type="text/javascript">

function submitTwice(f){

f.action = 'first.php';

f.submit();

f.action = 'second.php';

f.submit();

}

</script>

Thats it, But thanks Kor after all i got what i needed becaz of you.
Copy linkTweet thisAlerts:
@Sterling_IsfineApr 01.2010 — i've tried this ....

link 1 works when [I]"f.target='ifr*';"[/I] is included and link 2 works when it is deleted. They don't both work together.

anyone?[/QUOTE]
Some browsers may have a problem with queueing the data from two forms, so it's not entirely surprising that it failed and I don't think it could be considered reliable. If a JavaScript-dependent solution is acceptable, an AJAX routine would be far more dependable, but the best solution has to be a server-side forwarding script.
×

Success!

Help @lyleyboy 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 5.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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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