The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> FORMS - Multiple actions from a SUBMIT button
Shminglebaart
post Oct 6 2006, 11:09 AM
Post #1





Group: Members
Posts: 2
Joined: 6-October 06
Member No.: 351



Say I had a form on a site and when the used clicked SUBMIT, I wanted to perform TWO actions, I want it to go off and populate a database AND i want it to email the results elsewhere.

Is it possible to set two actions from a submit button?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Oct 6 2006, 11:27 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,653
Joined: 10-August 06
Member No.: 7



See http://htmlhelp.com/faq/html/forms.html#two-action
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
linus
post Feb 14 2011, 04:32 PM
Post #3





Group: Members
Posts: 1
Joined: 14-February 11
Member No.: 13,869



CODE
<html>
<head>
<script language="Javascript">
<!--
function OnButton1()
{
    document.Form1.action = "response1.php"
    // document.Form1.target = "_blank";    // Open in a new window

    document.Form1.submit();             // Submit the page

    return true;
}

function OnButton2()
{
    document.Form1.action = "response2.php"
    document.Form1.target = "_blank";    // Open in a new window

    document.Form1.submit();             // Submit the page

    return true;
}
-->
</script>
<noscript>You need Javascript enabled for this to work</noscript>
</head>
<body>
<!-- create the form -->
<form name="Form1" method="post">

<!-- Add the data entry bits -->
Your Name <input type="text" name="name" size="10" /><br />

<!-- Add some buttons -->
<INPUT type="button" value="Button1" name=name onclick="OnButton1(); OnButton2();">
<!-- close the form -->
</form>
</body>
</html>


i am working through the same issue... this form is working out for me so far.

This post has been edited by linus: Feb 14 2011, 04:32 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Feb 14 2011, 10:30 PM
Post #4


WDG Member
********

Group: Root Admin
Posts: 8,365
Joined: 4-August 06
From: Mountain View, CA
Member No.: 3



QUOTE
i am working through the same issue... this form is working out for me so far.
It won't work when JavaScript is disabled/unavailable.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Virendrasinh Gohil
post Apr 12 2011, 08:28 AM
Post #5





Group: Members
Posts: 1
Joined: 12-April 11
Member No.: 14,320



QUOTE(linus @ Feb 15 2011, 03:02 AM) *

CODE


function OnButton1()
    document.Form1.action = "response1.php"
    document.Form1.submit();             // Submit the page

function OnButton2()
    document.Form1.action = "response2.php"
    document.Form1.submit();             // Submit the page
<form name="Form1" method="post">
<INPUT type="button" value="Button1" name=name onclick="OnButton1(); OnButton2();">



How do I pass any extra information as parameter based on which function called?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
rodrigosieja
post Nov 19 2013, 01:23 PM
Post #6





Group: Members
Posts: 1
Joined: 19-November 13
Member No.: 20,009



QUOTE(Virendrasinh Gohil @ Apr 12 2011, 10:28 AM) *

QUOTE(linus @ Feb 15 2011, 03:02 AM) *

CODE


function OnButton1() {
    document.Form1.action = "response1.php"
    document.Form1.submit();             // Submit the page
}

function OnButton2() {
    document.Form1.action = "response2.php"
    document.Form1.submit();             // Submit the page
}
<form name="Form1" method="post">
<input type="button" value="Button1" name="name" onclick="OnButton1(); OnButton2();">



How do I pass any extra information as parameter based on which function called?


Maybe through GET method?

Example:

CODE

function OnButton1() {
    document.Form1.action = "response1.php?param=test"
    document.Form1.submit();             // Submit the page
}


And within response1.php:

CODE

$param = $_GET['param'];
if($param == 'test') {
echo 'Test passed<br /><br />';
} else {
echo 'Test failed<br /><br />';
}


This post has been edited by rodrigosieja: Nov 19 2013, 01:26 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 18th April 2024 - 11:35 PM