12

I have defined tab index for the input fields in a form. When tabbing through the input fields the submit button is never getting the focus, some other input fields in a different form on the page gets the focus. Those are all having tab indexes higher than 3. How come?

<form action="subscription.php" name="subscribe" method="post"  onsubmit="return isValidEmailAndEqual()">
<p id="formlabel">E-mail</p> <input type="text" name="email1" tabindex=1>

<br/>
<p id="formlabel">Repeat e-mail</p> <input type="text" name="email2" tabindex=2> <br/>
<input id="inputsubmit" type="submit" value="Subscribe" tabindex=3>
</form>

CSS:

input {
    background-color : #333;
    border: 1px solid #EEE;
    color: #EEE;
    margin-bottom: 6px;
    margin-top: 4px;
    padding: 1px;
    width : 200px;
}

#inputsubmit {
    background-color : #d7e6f1;
    border: 1px solid #EEE;
    color: #0000ff;
    margin-bottom: 6px;
    margin-top: 4px;
    padding: 1px;
    width : 200px;
}

#inputsubmit:hover {
    cursor: pointer; cursor: hand;  
    background-color : #d7e6f1;
    border: 1px solid #0000ff;
    color: #0000ff;
    margin-bottom: 6px;
    margin-top: 4px;
    padding: 1px;
    width : 200px;
}

p#formlabel{
    width: 100;
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
Nicsoft
  • 3,644
  • 9
  • 41
  • 70
  • I've tried your code and it "tabs" like it should. Maybe something else in your page is interfering with the correct tab-order? – Select0r Feb 25 '10 at 14:35
  • Thanks for your answer! Well, it doesn't work for sure (using Firefox). Could it have something to do with my style sheet? I updated my question with my style sheet. I am doing hovering-things for example, can it have any impact? – Nicsoft Feb 25 '10 at 14:41

4 Answers4

17

It's a Mac 'feature' to only let you tab thought input boxes and lists by default. Tabbing through all controls is an advanced option:

http://support.mozilla.com/en-US/kb/Pressing+Tab+key+does+not+select+menus+or+buttons

Firefox on Mac copies this default OS behavior.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Tom Wuttke
  • 868
  • 6
  • 4
  • 4
    Happens on Safari as well. I think it's a Mac thing rather - and then it's whether the browser obeys the OS preference. Going to Keyboard settings in Mavericks and then enabling "All controls" under Full Keyboard Access worked for me. – awidgery May 14 '14 at 10:54
14

This is a Mac OS X issue. Your Mac may be configured to not allow you to tab to non-textfield elements (e.g., buttons). You can change this by going into system preferences for keyboard. Then click on the shorcut tab and look at the bottom and choose the option to allow focus on all controls. You should now be able to focus on the buttons on Safari and Firefox in addition to all buttons in Mac OS.

To quickly change the setting on your Mac, press CTRL + F7 (or if you're using a Mac Keyboard, try holding down the Function Key and pressing CTRL + F7).

Sterling Bourne
  • 3,064
  • 23
  • 22
Rick
  • 141
  • 1
  • 2
4

Ok, let's see. I have tried above code in Firefox (Mac, Windows), Safari (Mac) and IE (Windows). Here are my findings:

When using

<button name="thename" type="submit">Subscribe</button>

or

<input id=\"inputsubmit\" type=\"submit\" value=\"Subscribe\">

for submitting the form (same result):

  • FF (Win) - When tabbing, the focus does hit the button
  • FF (Mac) - When tabbing, the focus is not hitting the button.
  • Safari (Mac) - When tabbing, the focus is not hitting the button.
  • IE (Win) - When tabbing, the button seems to be in some kind of focus all the time and the button will have some extra focus when tabbing to i.
  • For all, when an item inside the form has the focus it's possible to just hit enter in order to "click" the submit button.

I guess the conclusion has to be like this:

  1. Different browsers behave differently. Even the same browser behaves differently on different OS (FF).

  2. The default behaviour of a form is that hitting enter will submit the form using the first submit button in the form.

  3. I think it's a pitty that the focus wont hit the button when tabbing because I think that quite a lot of users expect the focus on the item before hitting enter.

Or what do you say...?

Nicsoft
  • 3,644
  • 9
  • 41
  • 70
  • 1
    1. I think it's the OS behavior that's different, not the browser. Notice in all Windows version browsers you get focus, while on Mac you don't. 2. It's not getting focus -- but the default behavior for a form is hitting enter submits it with the first submit button on the form. 3. Don't know about other users, but I expect to click enter when I'm done with the form, regardless of what's focused. – casraf Feb 26 '10 at 09:46
  • 2. I updated my answer to reflect your comment. 3. I usually tab to the button and then hit enter, but my mom tells me I am unique so... – Nicsoft Feb 26 '10 at 10:06
  • Haha. Well, maybe you are ;) it's a minor problem, and since I don't have a Mac I can't really see it happening real-time -- so I think that's as far as I can hypothetically help you right now. – casraf Feb 26 '10 at 10:16
  • Hehe... Thank you for helping out, the discussion helped me understand what is possible and not. – Nicsoft Feb 26 '10 at 13:27
-1

You don't have to define tab indexes, you might as well give them up -- unless you want to modify the natural order of them when they get sorted by their creation. Try taking them out altogether and see if it works more to your liking.

casraf
  • 21,085
  • 9
  • 56
  • 91
  • Actually I didn't have any tabindexes defined before. But since it wasn't possible to tab to the submit button I thought I had to add tabindexes. But it still didn't help. I updated my question with my style sheet data, at least part of it... Don't know if that matters? – Nicsoft Feb 25 '10 at 14:43
  • It focuses for me both in Firefox and Chrome -- do you think maybe you just can't visibly see it? Try adding a third style for `#inputsubmit:focus` and see if it works. – casraf Feb 25 '10 at 17:05
  • I can actually see that another input field in a different form is getting the focus. The cursor is flashing in that input field. I tried adding the #inputsubmit:focus style, but it is not triggered while tabbing. I tried it on safari as well, but no luck. Sitting on a Mac, but it shouldn't make any difference I assume... – Nicsoft Feb 26 '10 at 07:13
  • Are you sure their natural order should have it focused? Also, try tabbing a lot till you loop the fields -- does it *ever* get focused? – casraf Feb 26 '10 at 08:39
  • No, it never gets the focus, at least not FF on Mac. Check my own answer. Is it really possible to do this for all browsers on both Mac and Win? – Nicsoft Feb 26 '10 at 09:36
  • @henasraf - this is a Mac "feature". – Andrew Jul 22 '10 at 01:32