473,796 Members | 2,482 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

two or more buttons in a form; keyboard enter/return activates which button

88 New Member
If you have a form with x input and two or more buttons, how do you control which button has preceding when the user hits the keyboard key "enter"?

Currently it seems to be determined in a hierarchical manner.

E.g.

[HTML]

<form>

<input />
<input />

<button name="1" value="a" />
<button name="1" value="b" />
<button name="1" value="c" />

</form>

[/HTML]

When the user hits enter, button nr 1 will be activated, and value "a" will automatically be chosen as the default value (which is sent to PHP). How do you control this event so that button value "b" or "c" is activated instead?

(comp. to a situation as '<input type="hidden" name="1" value="a"/><input type="text" name="1" value="b"/>' where b would be the default)

I know you can handle this problem with javascript but I want to know if this can be handled with PHP.

How did the "designers of the HTML form functionality" perceive the use of several buttons?
May 17 '08 #1
7 3145
dlite922
1,584 Recognized Expert Top Contributor
If you have a form with x input and two or more buttons, how do you control which button has preceding when the user hits the keyboard key "enter"?

Currently it seems to be determined in a hierarchical manner.

E.g.

[HTML]

<form>

<input />
<input />

<button name="1" value="a" />
<button name="1" value="b" />
<button name="1" value="c" />

</form>

[/HTML]

When the user hits enter, button nr 1 will be activated, and value "a" will automatically be chosen as the default value (which is sent to PHP). How do you control this event so that button value "b" or "c" is activated instead?

(comp. to a situation as '<input type="hidden" name="1" value="a"/><input type="text" name="1" value="b"/>' where b would be the default)

I know you can handle this problem with javascript but I want to know if this can be handled with PHP.

How did the "designers of the HTML form functionality" perceive the use of several buttons?
PHP has nothing to do with how HTML behaves and submits the for. All PHP gets is an array of elements.

In your example, its the browser behaving that way, there is a possibility some other browser submits the last button instead of the first when you press enter.

This can be handled by javascript. Describe what factors are involved in deciding what button to press and we can help you in the javascript forum.

Rov... please move this to JS forum to further disect this problem.

If they don't help you there, PM me and I'll come there (I usually stay in PHP forum)
May 17 '08 #2
ManWithNoName
88 New Member
Thanks for your quick reply and input.

First, js is (currently) out of the question, this need to be on the server side.

What I am trying to do is this:

I have have a form with x steps.

Each steps have a previous and next button.

When/if the users presses "enter" on step 1, the user is taken to step 2.

When/if the user presses "enter" in step 2, the user is now however taken back to step 1.

The reason is that the previous button comes before the next button (the thing being people reading from left to right in this part of the world).

I get the _POST correctly in php, and I could put a conditional statement and all... However, I do not know if the user has pressed the "enter" key or the submit button.

I was hoping this could be done with hidden forms or something; I need to "catch" the enter key...
May 17 '08 #3
ManWithNoName
88 New Member
This is the closest thing I found which implies that it is possible to do this:

3. Test for form submission with a hidden element.

Include a hidden variable named, say, _submit_check in your forms like this:

<input type="hidden" name="_submit_c heck" value="1"/>

Then, to test whether the form has been submitted, look for the _submit_check element in $_POST:

if (array_key_exis ts('_submit_che ck', $_POST)) {
/* ... do something with the form parameters ... */
}

Testing for the presence of a hidden element avoids problems that can result from browsers' varying behaviors when a user submits a form by pressing the Enter key instead of clicking a submit button.
From http://www.onlamp.com/pub/a/php/2004...mhandling.html

This should solve my problem:

"Testing for the presence of a hidden element avoids problems that can result from browsers' varying behaviors when a user submits a form by pressing the Enter key instead of clicking a submit button"

But I don't understad what they are talking about.

I have a hidden input for the form name, but it will end up in the $_POST var regardless if the user presses submit or enter, no?
May 17 '08 #4
Atli
5,058 Recognized Expert Expert
The problem is, that not all browsers handle forms submitted this way in the same manner.
IE, for example, will submit it without any of the submit buttons, while Firefox will submit by using the first button in the form.

You could put a hidden element inside your form, and have each of your submit buttons change it's value via the onmousedown event before submitting.
By using the onmousedown event, the value won't be changed unless the user actually presses the button. The onclick event won't work, as it is triggered by Firefox when the enter button is pressed.

Then, using PHP, you could proceed based on the value of your hidden element.
If the user submits by clicking enter, the default value of the hidden element would remain unchanged.
May 18 '08 #5
ManWithNoName
88 New Member
Thanks for your input Atli!

"By using the onmousedown event, the value won't be changed unless the user actually presses the button. The onclick event won't work, as it is triggered by Firefox when the enter button is pressed."

I didn't know that, good stuff.

All in all, interesting solution, but like I said earlier, I wanted to avoid all that is JS for this problem.

The idea with "hidden forms" in that article I linked to is -- in my opinion -- all bollocks. However, it gave me another idea...

I created a new button before my other buttons, named it X and hid it using CSS (display:none).

Now when the user presses Enter in FF the x button is read and sent, I just pick it up.

IE, as you pointed out, doesn't pick up the button when the user presses Enter, so I just check if X isset and if no; if no I'll know the user pressed Enter.

I feel so smart ^.^
May 18 '08 #6
dlite922
1,584 Recognized Expert Top Contributor
If you want to stick with your original idea that browsers will choose the first (submit) button then you could do just that.

Put the next button first, however reload them with CSS.

Can you atleast use CSS?
May 20 '08 #7
ManWithNoName
88 New Member
If you want to stick with your original idea that browsers will choose the first (submit) button then you could do just that.

Put the next button first, however reload them with CSS.

Can you atleast use CSS?
CSS is good to go.

But what do you mean with "reload them with CSS" ???
May 20 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
8177
by: Newbie | last post by:
I currently have a set of simple calculations to determine square footage and multuply that by a dollar amount per foot. I use form fields that are filled in by the user, and then the Submit button opens the asp page that returns the result of the calculation. What I would like to do is add certain numbers to the total based on radio buttons or checkboxes that the user activates on the form page. For instance, they enter the numbers into...
3
7399
by: BruceR | last post by:
I have posted a similar message and am reposting due to no response. Basically, I need to know why using the ampersand to indicate an access key for a button makes it so that simply entering the key alone selects the button. It should be that the user must press Alt + the access key. Note that this works also, it is just that I need it to NOT select the button if the user enters JUST the access key. My problem is that my application has...
0
7982
by: Hiroyuki Tanaka | last post by:
Hi, I am trying to develop an application for a touch screen using buttons for the numeric pad with Completion ComboBoxes. At the moment I am having a problem sending the button presses to my Completion ComboBox using sendkey.wait. From the keyboard (that will not exist for my final application) I can enter text into my Completion and the selection completes as expected.
0
2668
by: Hiroyuki Tanaka | last post by:
Hi All, I am trying to develop an application for a touch screen using buttons for the numeric pad with Completion ComboBoxes. At the moment I am having a problem sending the button presses to my Completion ComboBox using sendkey.wait. From the keyboard (that will not exist for my final application) I can enter text into my Completion and the selection completes as expected.
1
1362
by: ravindradonkada | last post by:
Hi, I am Ravindra,presently doing a project in asp.net. The Login page of my Web Project consists of two Buttons. If user enters his username and password and clicks on enter button of keyboard, the Signin button is to be submitted not the other button. So,please specify how to get focus on the specified Button Thanks in advance.
1
1103
by: Peted | last post by:
I have a form with 8 checkbuttons in "button" apearence mode each button press activates a relay device on a connected piece of hardware. For the relay device to activate a specfic relay it needs to get a number of the relay to be used from the button pressed EG press button 1, activates relay number 1, button 2 activates relay 2.
6
4933
by: Paul Furman | last post by:
I'm getting incorrect response when hitting the enter key instead of actually clicking the button on a form. It activates but the post data isn't being sent I think. The php generated page flickers & reloads but doesn't perform the update. This is php generated, I'm just pasting the page source (reformatted & extra junk removed and I think they are now identical), and it's running on my localhost apache server for testing so maybe...
6
3902
by: =?Utf-8?B?L2Rldi9udWxs?= | last post by:
Hello, i am using visual studio 2003 enterprise architect version. I am making apps for the .Net framework 1.1. While testing an interface, i discovered something strange. In this application we have a standard toolbar that is at the top of the form window. It contains about 8 buttons that use images from an imagelist. Sometimes we hide buttons thru the code. When a button is hidden, i assumed that it wasn't clickable. It appears
6
1841
by: Omicron | last post by:
Hello, Can someone lead me in the right direct with this request: Please look at the piece of code below: <table summary="Sort Buttons"> <tr> <td> <input onclick="justSong_filter()" type="button" value="Song Search" / <input type="text" id="newSong" /> </td>
0
9673
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, 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...
0
9525
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
10452
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...
0
10221
jinu1996
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...
0
10003
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
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
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.