472,958 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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 6362
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
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
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
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
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
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
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
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
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.