473,657 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

through which submit button the form was submitted

I have a HTML page containing two submit buttons in the same form.When
the form is submitted,I want to know through which submit button the
form was submitted.
Is there any event or property which identifies this?

Apr 5 '06 #1
6 2147
you can asign different IDs to both the buttons and invoke appropriate
methods for each button's onsubmit event ....

Apr 5 '06 #2
VK

st*********@gma il.com wrote:
I have a HTML page containing two submit buttons in the same form.When
the form is submitted,I want to know through which submit button the
form was submitted.
Is there any event or property which identifies this?


Unfortunately no - event model creators overlooked the variant of
multiple submit buttons in the form. onsubmit event contains FORM as
target/srcElement, so you cannot backtrace the pressed button.

Luckely click event is being processed before submit. So in your form:

<form action="foo.cgi " onsubmit="retur n validate(this)" >
....
<input type="submit" name="act" value="Submit 1"
onclick="glbAct =this;">
<input type="submit" name="act" value="Submit 2"
onclick="glbAct =this;">
</form>

Now in validate() you can check global variable glbAct to find which
button was pressed.

Apr 5 '06 #3
as we are the middleware securing the backend application,we can't
able to change the html code in the backend application.
so we need to trace the details of the 'submit' button, when the form
submission was made .
(without adding anyother extra event handling ..like onclick())

Apr 5 '06 #4
st*********@gma il.com wrote:
as we are the middleware securing the backend application,we can't
able to change the html code in the backend application.
so we need to trace the details of the 'submit' button, when the form
submission was made .
(without adding anyother extra event handling ..like onclick())


In the HTML, give each submit button a different name and value.
Whichever one is clicked will send its name-value pair.

From the spec:

"If a form contains more than one submit button, only the
activated submit button is successful."

<URL:http://www.w3.org/TR/html401/interact/forms.html#subm it-format>
You can add onclick attributes using script without modifying the HTML
at all (other than to add the script element of course), but don't make
your form submission script dependent.
--
Rob
Apr 5 '06 #5
If there are two submit buttons and your "method" attribute of your
form is "get" then the submitted buttons name and value appear as query
string parameters. Where as the one that is not submitted dont appear
in the query string.

This is possible when the button type is "submit".

Now if the button type is "image" then the workaround is different. I
was in a similar situation with some contraints. The constraints were -
no javascript to be used, no submit buttons but image buttons, and php
as the backend technology.

the HTML code was as below:
<Form method = post action="some.ph p">
<input type="image" name="n1[]" value="n1"/>
<input type="image" name="n2[]" value="n2"/>
</Form>

Now within "some.php" I can check which one of the image buttons was
clicked:

if($_REQUEST["n1"] == true){
//do something
} else if($_REQUEST["n2"] == true){
//do something else
}

In this case the names are treated as arrays. when the button is
clicked the array is populated.
$_REQUEST["n1"] == true checks that.

----------
Arvind

Apr 7 '06 #6
ar******@yahoo. com wrote:
Now if the button type is "image" then the workaround is different. I
was in a similar situation with some contraints. The constraints were -
no javascript to be used,
Nonsense. The two technologies are independent of one another.
[...]
<Form method = post action="some.ph p">
<input type="image" name="n1[]" value="n1"/>
<input type="image" name="n2[]" value="n2"/>
</Form>

Now within "some.php" I can check which one of the image buttons was
clicked:

if($_REQUEST["n1"] == true){
//do something
} else if($_REQUEST["n2"] == true){
//do something else
}


You were looking for

if (isset($_POST['n1']))

of course. And it is not necessary that the name ends with '[]'.
PointedEars
Apr 7 '06 #7

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

Similar topics

3
6584
by: Nicolas Keller | last post by:
Hi! I'm used to have Mozilla for testing my PHP sites when I'm coding. The site's nearly finished, now I've made a test with the Internet Exlporer... guess what... failed. The problem: I'm using a form that submit's (POST) its data via three different image buttons (depending on which button you click, something different should happen):
15
28948
by: Mattia | last post by:
Hi! I have a <form> that can be submitted thruogh three buttons and I need to tell witch one was pressed when the form was submitted. I now do it with 3 <input type="submit" name="..." value="..."> with <input type="submit" ...> the only name-value values submitted (pushed into the query string) is the one of the submit button that was pushed (if you have many of them). Ex:
3
4341
by: John Dunlop | last post by:
(Note crosspost and follow-ups to ciwah.) Nicolas Keller wrote in thread "Differences in form handling btw Mozilla and IE?": > The problem: I'm using a form that submit's (POST) its data via three > different image buttons (depending on which button you click, > something different should happen): > > <form action="id.php" method="post" name="form2">
2
9586
by: ivanhoe | last post by:
All articles and tutorials I've seen on subject of forms say that if there's name and value for submit button(input tag with type="submit"), they'll get submitted along with the rest of the form... but I've just noticed (after debugging my perl script for quite a while :/ ) that it is true only when user clicks on submit, and if form is submitted via hitting enter you don't get name=value for submit buttton...
2
4892
by: Margaret Werdermann | last post by:
Hi all: I'm having a nasty time with a particularly difficult piece of code and was hoping someone might be able to help me. I have a FormMail form that originally worked perfectly. Then, I had to add a JavaScript function to the Submit button to make a server function run when the form was submitted. Unfortunately, this JavaScript wouldn't run when the button was designated as a Submit, so I changed the button and placed a...
8
6184
by: bettina | last post by:
I want to submit a form but without a submit button. That's to say, I want that by giving a definite code in a field and then press <ENTER> the form will be submitted. For Example <form name="search_form" method="post" action="search.php"> ..... .... Code: <input type="text" name="code" onKeyPress="if (event.keyCode == 13) {document.search_form.submit()};">
2
3810
by: anonieko | last post by:
Scenario: You have a page that is TOO slow to refresh. But it allows partial flushing of html contents. I.e. Submit button already appears but you don't want your users to click on it prematurely because other parts are still coming. Here I put a javascript the will enable only submit button only after 5 seconds after the page is load fully.
3
1890
by: Taras_96 | last post by:
Hi everyone, I've got a rather unconventional architecture that I'm having problems with... I have a form called "searchForm", that has an input of type "submit" (with name = "submitButton for argument sake). What happens when the form is submitted (when the submit button is clicked...) depends on some previous user input. In one case, the onsubmit handler calls a function that does basic input checking, and returns true if all the
5
7521
by: g | last post by:
Hi Guys.. i know this might sound really really simple, but I'm kinda stuck..I have this form..which has a table (created from stored procedure values)..once the table is populated..i have some radio buttons (for each row of the table) and a main submit button. On clicking submit..i want to loop through the table..pick up the first <TDbeing the user ID and the value of the radio button clicked (currently I have my radio button ID set...
0
8316
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8509
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,...
0
7345
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, 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...
1
6174
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 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...
0
4168
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...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
bsmnconsultancy
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...

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.