473,503 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conditional onsubmit events

Hi,

I have a form that has 2 submit buttons. The form action is a php
script. What I'm trying to do is to execute a different javascript
function depending on which submit button is pressed. So far I've tried
the following with no success. In the code below, a different function
would execute based on the value of the "flag" variable.

<HTML>
<HEAD>
<SCRIPT TYPE="text/javascript">
function some_function() {
alert(flag);
}
</SCRIPT>
</HEAD>
<BODY>
<form name="form1" action="./submit.php" method="POST"
onsubmit="javascript:some_function()">
<input type="text" name="name" size=50>
<input type="submit" name="submit1" value="Submit 1"
onclick="javascript:var flag=1;">
<input type="submit" name="submit2" value="Submit 2"
onclick="javascript:var flag=2;">
</form>
</BODY>
</HTML>
<?php
if ($_POST[submit1]) {
echo "submit1";
}

if ($_POST[submit2]) {
echo "submit2";
}
?>

Aug 24 '05 #1
5 6373
tom
Hello,
you sholud try this
first write this function into head section
function checkpressedbtn(obj)
{
if (obj.value == "Submit 1")
------- go to your function -----------
else
------- go to another function -----------
}

then change your buttons like this
input type="submit" name="submit1" value="Submit 1"
onclick="javascript: checkpressedbtn(this)">
<input type="submit" name="submit2" value="Submit 2"
onclick="javascript: checkpressedbtn(this)">
Raffi wrote:
Hi,

I have a form that has 2 submit buttons. The form action is a php
script. What I'm trying to do is to execute a different javascript
function depending on which submit button is pressed. So far I've tried
the following with no success. In the code below, a different function
would execute based on the value of the "flag" variable.

<HTML>
<HEAD>
<SCRIPT TYPE="text/javascript">
function some_function() {
alert(flag);
}
</SCRIPT>
</HEAD>
<BODY>
<form name="form1" action="./submit.php" method="POST"
onsubmit="javascript:some_function()">
<input type="text" name="name" size=50>
<input type="submit" name="submit1" value="Submit 1"
onclick="javascript:var flag=1;">
<input type="submit" name="submit2" value="Submit 2"
onclick="javascript:var flag=2;">
</form>
</BODY>
</HTML>
<?php
if ($_POST[submit1]) {
echo "submit1";
}

if ($_POST[submit2]) {
echo "submit2";
}
?>


Aug 24 '05 #2
Lee
Raffi said:

Hi,

I have a form that has 2 submit buttons. The form action is a php
script. What I'm trying to do is to execute a different javascript
function depending on which submit button is pressed. So far I've tried
the following with no success. In the code below, a different function
would execute based on the value of the "flag" variable.


Get rid of the "javascript:" labels and the "var" keyword, which
makes the flag variable local. You want it to be global.

<HTML>
<HEAD>
<SCRIPT TYPE="text/javascript">
function some_function() {
alert(flag);
}
</SCRIPT>
</HEAD>
<BODY>
<form name="form1" action="./submit.php" method="POST"
onsubmit="some_function()">
<input type="text" name="name" size=50>
<input type="submit" name="submit1"
value="Submit 1" onclick="flag=1;">
<input type="submit" name="submit2"
value="Submit 2" onclick="flag=2;">
</form>
</BODY>
</HTML>

Aug 24 '05 #3

Lee wrote:
Raffi said:

Hi,

I have a form that has 2 submit buttons. The form action is a php
script. What I'm trying to do is to execute a different javascript
function depending on which submit button is pressed. So far I've tried
the following with no success. In the code below, a different function
would execute based on the value of the "flag" variable.


Get rid of the "javascript:" labels and the "var" keyword, which
makes the flag variable local. You want it to be global.

<HTML>
<HEAD>
<SCRIPT TYPE="text/javascript">
function some_function() {
alert(flag);
}
</SCRIPT>
</HEAD>
<BODY>
<form name="form1" action="./submit.php" method="POST"
onsubmit="some_function()">
<input type="text" name="name" size=50>
<input type="submit" name="submit1"
value="Submit 1" onclick="flag=1;">
<input type="submit" name="submit2"
value="Submit 2" onclick="flag=2;">
</form>
</BODY>
</HTML>


Thanks, I will give these a try.

Raffi

Aug 25 '05 #4
Lee wrote:
Raffi said:
Hi,

I have a form that has 2 submit buttons. The form action is a php
script. What I'm trying to do is to execute a different javascript
function depending on which submit button is pressed. So far I've tried
the following with no success. In the code below, a different function
would execute based on the value of the "flag" variable.

Get rid of the "javascript:" labels and the "var" keyword, which
makes the flag variable local. You want it to be global.

<HTML>
<HEAD>
<SCRIPT TYPE="text/javascript">
function some_function() {
alert(flag);
}
</SCRIPT>
</HEAD>
<BODY>
<form name="form1" action="./submit.php" method="POST"
onsubmit="some_function()">
<input type="text" name="name" size=50>
<input type="submit" name="submit1"
value="Submit 1" onclick="flag=1;">
<input type="submit" name="submit2"
value="Submit 2" onclick="flag=2;">
</form>
</BODY>
</HTML>


The form might be submitted without either onclick function running - it
may be submitted by pressing the enter key or javascript may be disabled
or unavailable.

--
Rob
Aug 25 '05 #5

RobG wrote:
Lee wrote:
Raffi said:
Hi,

I have a form that has 2 submit buttons. The form action is a php
script. What I'm trying to do is to execute a different javascript
function depending on which submit button is pressed. So far I've tried
the following with no success. In the code below, a different function
would execute based on the value of the "flag" variable.

Get rid of the "javascript:" labels and the "var" keyword, which
makes the flag variable local. You want it to be global.

<HTML>
<HEAD>
<SCRIPT TYPE="text/javascript">
function some_function() {
alert(flag);
}
</SCRIPT>
</HEAD>
<BODY>
<form name="form1" action="./submit.php" method="POST"
onsubmit="some_function()">
<input type="text" name="name" size=50>
<input type="submit" name="submit1"
value="Submit 1" onclick="flag=1;">
<input type="submit" name="submit2"
value="Submit 2" onclick="flag=2;">
</form>
</BODY>
</HTML>


The form might be submitted without either onclick function running - it
may be submitted by pressing the enter key or javascript may be disabled
or unavailable.

--
Rob


Thanks for all the suggestions. I got it working through some additions
and changes to my original script. I prefer not to put the code online
since the objective was to partially work around popup blockers while
conditionally redirecting the application via a popup window, and at
the same time posting the data to a server side php script. I'd rather
keep these types of scripts off the newsgroups and out of the hands of
potential abusers.

Raffi

Aug 26 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2294
by: Sjon | last post by:
Here's A piece of my code: <form action="dimensions.php" method="POST"> <br><input type="radio" style="background : #84c7e8" name="categorie" value="Customer" checked> Customer</br> <br><input...
28
3414
by: Benjamin Niemann | last post by:
Hello, I've been just investigating IE conditional comments - hiding things from non-IE/Win browsers is easy, but I wanted to know, if it's possible to hide code from IE/Win browsers. I found...
4
10125
by: usl2222 | last post by:
Hi folks, I appreciate any assistance in the following problem: I have a form with a bunch of dynamic controls on it. All the controls are dynamically generated on a server, including all...
8
8461
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
1
1927
by: vunet | last post by:
I write a JS library component which is applied to every form on a webpage. The component does something before it submits the form. Now, let's say user has his own onSubmit() handlers returning...
1
6356
by: pechar | last post by:
Hi all, I'm absolutely lost and have no idea why this is happening. I have a master page where the form resides. I set an onsubmit attribute to call a method which sets a variable to true ...
7
4301
by: tiptap | last post by:
Hey Guys, I have a huge statement loads of if statements in... and its getting bigger. On closer inspection there is only 3 difference in the select statement. so I thought I could cut the...
2
4758
by: rudiedirkx | last post by:
Gents, I have a problem (only in Safari) with the onsubmit in webforms. This topic covers the same subject: http://bytes.com/topic/javascript/answers/166542-onsubmit-safari but not as detailed as...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7456
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.