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="javas cript:some_func tion()">
<input type="text" name="name" size=50>
<input type="submit" name="submit1" value="Submit 1"
onclick="javasc ript:var flag=1;">
<input type="submit" name="submit2" value="Submit 2"
onclick="javasc ript:var flag=2;">
</form>
</BODY>
</HTML>
<?php
if ($_POST[submit1]) {
echo "submit1";
}
if ($_POST[submit2]) {
echo "submit2";
}
?> 5 6391
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="javasc ript: checkpressedbtn (this)">
<input type="submit" name="submit2" value="Submit 2"
onclick="javasc ript: 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="javas cript:some_func tion()"> <input type="text" name="name" size=50> <input type="submit" name="submit1" value="Submit 1" onclick="javasc ript:var flag=1;"> <input type="submit" name="submit2" value="Submit 2" onclick="javasc ript:var flag=2;"> </form> </BODY> </HTML>
<?php if ($_POST[submit1]) { echo "submit1"; }
if ($_POST[submit2]) { echo "submit2"; } ?>
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>
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 type="radio" style="background : #84c7e8" name="categorie"
value="Employee"> Project Manager</br>
<br><input type="radio" style="background : #84c7e8" name="categorie"
value="Vendor" > Vendor</br>
<br><input type="submit" name="submitknop"...
|
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 <!> in the original MSDN documentation, but this is (although
it is working) unfortunately non-validating gibberish.
So I fooled around trying to find a way to make it valid. And voila:
<!--><!><!-->
|
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 the validators.
The user enters the data, presses OK. My OK button is dynamically
generated as well, with some code-behind logic in
|
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
perfectly. However, I have code that runs under the ON CLICK event. The
code changes the focus to other controls, which means the conditional
formatting is no longer displayed. This part makes sense to me.
Here's what doesn't make sense. The last...
|
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 true or
false. I want to find a way to add my component's "onsubmit" event to
the form without overwriting user-defined onSubmit() handlers or
onsubmit events.
Is there a really good way of doing this?
The problem I've come across was if I add...
| |
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
<form id="form1" runat="server" onsubmit="setVariable();">
the function I call is :
function setVariable()
|
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 whole thing down to just 1 select statement if I have a conditional Having.
I've simplified the IF statement down a bit to give you an idea of what im trying to achieve
IF @month <> 0 & @diffFuture = 0 & @showDate <> 0
|
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 I will.
Let me illustrate the problem with examples.
The HTML:
<html>
<head>
<script type="text/javascript" src="/js/mootools_1_11.js"></script>
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |