473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Form Submit Button Question

Hi,

For a web page, I want a SUBMIT button that commits the form data and a
CANCEL button that goes to a different target (i.e. a different script).

I haven't figured out how to do this, because the <FORM ACTION="... tag
seems to make sure that any two submit controls in a form have to go to the
same target.

BTW, the CANCEL button does not have to submit any form data.

Thanks, Dave.

Jul 5 '06 #1
7 2335
David T. Ashley wrote:
Hi,

For a web page, I want a SUBMIT button that commits the form data and a
CANCEL button that goes to a different target (i.e. a different script).

I haven't figured out how to do this, because the <FORM ACTION="... tag
seems to make sure that any two submit controls in a form have to go to the
same target.

BTW, the CANCEL button does not have to submit any form data.

Thanks, Dave.
You're on the right track.

Submitting a form will *always* submit the form data, be grateful as
that is what we will use.

In your PHP script do something like:

// Was the value of the submit button 'Submit' ?
if( $_POST['submit'] === 'Submit') {
// Process your form
}
// Was the value of the submit button 'Cancel' ?
elseif( $_POST['submit'] === 'Cancel') {
// Redirect to another page or include a different script or any other
way you want to do your cancel action
}

Hope this helps !
Grz, Juliette
Jul 6 '06 #2

David T. Ashley wrote:
Hi,

For a web page, I want a SUBMIT button that commits the form data and a
CANCEL button that goes to a different target (i.e. a different script).

I haven't figured out how to do this, because the <FORM ACTION="... tag
seems to make sure that any two submit controls in a form have to go to the
same target.

BTW, the CANCEL button does not have to submit any form data.

Thanks, Dave.
javascript will do it.

Jul 6 '06 #3
flamer wrote:
David T. Ashley wrote:

>Hi,

For a web page, I want a SUBMIT button that commits the form data and a
CANCEL button that goes to a different target (i.e. a different script).

I haven't figured out how to do this, because the <FORM ACTION="... tag
seems to make sure that any two submit controls in a form have to go to the
same target.

BTW, the CANCEL button does not have to submit any form data.

Thanks, Dave.

javascript will do it.

To clarify that a bit more - do not put an action in the form tag. Use a
Javascript Onclick event on each button to set form.action.

The easiest method, however, since you do not need to submit any data on
Cancel, is to simply use two forms.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Everyone's journey should be different,
so that we all are enriched
in new and endless ways
*****************************
Jul 6 '06 #4

"Chuck Anderson" <we************@seemy.sigwrote in message
news:xv******************************@comcast.com. ..
>>
javascript will do it.

To clarify that a bit more - do not put an action in the form tag. Use a
Javascript Onclick event on each button to set form.action.
The recommended Javascript worked great.

Just one question ... my form buttons are "Change Password" and "Cancel", in
that order. When I hit ENTER on the computer keyboard, both IE and Mozilla
Firefox choose the "Change Password" button (I assume because it is the
first button in the form).

Is that the reason ENTER chooses one button (because it is first on the
form)?

Can this order or selection be modified?

Thanks.

Jul 6 '06 #5
no that is set in the browser, by default hitting enter is the same as
pressing submit.. HOWEVER.. fyi: when you press submit in the POST data
then $_POST[submit]=submit but if they press enter (only in IE) then
$_POST[submit] is not set..

thats off topic but can cause some confusion if in your scripts you use
if (isset($_POST['submit'])) { process form }

because if they hit enter rather than clicking submit then it wont be
set ect.. (use a hidden form field and check if that is set instead)

Flamer.

David T. Ashley wrote:
"Chuck Anderson" <we************@seemy.sigwrote in message
news:xv******************************@comcast.com. ..
>
javascript will do it.

To clarify that a bit more - do not put an action in the form tag. Use a
Javascript Onclick event on each button to set form.action.

The recommended Javascript worked great.

Just one question ... my form buttons are "Change Password" and "Cancel", in
that order. When I hit ENTER on the computer keyboard, both IE and Mozilla
Firefox choose the "Change Password" button (I assume because it is the
first button in the form).

Is that the reason ENTER chooses one button (because it is first on the
form)?

Can this order or selection be modified?

Thanks.
Jul 6 '06 #6
flamer di******@hotmail.com wrote:
no that is set in the browser, by default hitting enter is the same as
pressing submit.. HOWEVER.. fyi: when you press submit in the POST data
then $_POST[submit]=submit but if they press enter (only in IE) then
$_POST[submit] is not set..

thats off topic but can cause some confusion if in your scripts you use
if (isset($_POST['submit'])) { process form }

because if they hit enter rather than clicking submit then it wont be
set ect.. (use a hidden form field and check if that is set instead)

Flamer.

David T. Ashley wrote:
>"Chuck Anderson" <we************@seemy.sigwrote in message
news:xv******************************@comcast.com ...
>>>javascript will do it.
To clarify that a bit more - do not put an action in the form tag. Use a
Javascript Onclick event on each button to set form.action.
The recommended Javascript worked great.

Just one question ... my form buttons are "Change Password" and "Cancel", in
that order. When I hit ENTER on the computer keyboard, both IE and Mozilla
Firefox choose the "Change Password" button (I assume because it is the
first button in the form).

Is that the reason ENTER chooses one button (because it is first on the
form)?

Can this order or selection be modified?

Thanks.
Hmm.. don't know which version of IE you are using, but your comment
made me test a private script which I until now had only used in FF.
The script uses the $_POST['submit'] value to determine what to do as
there are three different forms on the page.
No matter which form I changed and then submitted with the ENTER button,
the resulting page showed that the requested action had been properly
taken, i.e. the value of the Submit button has been passed on properly.

Tested with IE6.

Grz, Juliette
Jul 7 '06 #7
Juliette wrote:
flamer di******@hotmail.com wrote:
no that is set in the browser, by default hitting enter is the same as
pressing submit.. HOWEVER.. fyi: when you press submit in the POST data
then $_POST[submit]=submit but if they press enter (only in IE) then
$_POST[submit] is not set..

thats off topic but can cause some confusion if in your scripts you use
if (isset($_POST['submit'])) { process form }

because if they hit enter rather than clicking submit then it wont be
set ect.. (use a hidden form field and check if that is set instead)

Flamer.

David T. Ashley wrote:
"Chuck Anderson" <we************@seemy.sigwrote in message
news:xv******************************@comcast.com. ..
javascript will do it.
To clarify that a bit more - do not put an action in the form tag. Use a
Javascript Onclick event on each button to set form.action.
The recommended Javascript worked great.

Just one question ... my form buttons are "Change Password" and "Cancel", in
that order. When I hit ENTER on the computer keyboard, both IE and Mozilla
Firefox choose the "Change Password" button (I assume because it is the
first button in the form).

Is that the reason ENTER chooses one button (because it is first on the
form)?

Can this order or selection be modified?

Thanks.

Hmm.. don't know which version of IE you are using, but your comment
made me test a private script which I until now had only used in FF.
The script uses the $_POST['submit'] value to determine what to do as
there are three different forms on the page.
No matter which form I changed and then submitted with the ENTER button,
the resulting page showed that the requested action had been properly
taken, i.e. the value of the Submit button has been passed on properly.

Tested with IE6.

Grz, Juliette
Ok must have been fixed then, because this test was <5.5
untested on other browsers.

Flamer.

Jul 7 '06 #8

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

Similar topics

3
by: Michele | last post by:
Hi all, I have a form with 3 combobox whitin a asp page called data.asp, whose action form is itself; the first combobox drives the behaviour of the other two. The onchange event of the first...
6
by: CJM | last post by:
Can somebody clarify if/how/when a simple form is submitted when the <Enter> key is pressed? As I understood it, if you have a form with a single submit button, if enter is pressed, the form...
5
by: Don | last post by:
I have a need to submit a form, but don't need the user to click on a button. How do I do this? Is there some way, using JavaScript, to setup a <form> tag to do this? Thanks, Don ----==...
2
by: Nick Bell | last post by:
I have a general form validation question. I know very little about javascript, a little more about PHP. Using yav (http://yav.sourceforge.net): <form method="POST" name=edit onsubmit="return...
0
by: 42 | last post by:
I implemented a simple class inherited from Page to create a page template. It simply wraps some trivial html around the inherited page, and puts the inherited page into a form. The problem I...
3
by: User | last post by:
Form A (Main) Text Box 1 Text Box 2 Text Box 3 Form B (Pop-up) Choose a selection for Form A/Text Box 3 Scenario:
9
by: Veerle | last post by:
Hi, When you use multiple asp:Buttons on one Form, then asp.net generates html submit buttons for all of them. When you put your cursor in one of the textfields of the form, the default submit...
5
by: plumba | last post by:
Hi all I have a form (see below), which for some reason has decided to stop functioning all together. It just does not call up the function. It is called up in the opening <form> tag but...
13
by: Andrew Falanga | last post by:
HI, Just a warning, I'm a javascript neophyte. I'm writing a function to validate the contents of a form on a web page I'm developing. Since I'm a neophyte, this function is quite simple at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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
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,...

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.