views:

600

answers:

5

Hello,

I have defined tabindex 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 tabindexes 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;

}

Thanks in advance!

A: 

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.

henasraf
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
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.
henasraf
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
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?
henasraf
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
@henasraf - this is a Mac "feature".
Andrew
A: 

I have 2 suggestions:

  • use "" - tabindex="1"
  • use button - <button name="thename" type="submit">Subscribe</button>
Knu
Thanks for your answer. I tried both of your answers, but it didn't work. The button is not getting the focus. I did like this for your other suggestions, guess the small difference shouldn't matter, the point is to use a button i guess... <button id=\"inputsubmit\" type=\"submit\">Subscribe</button>
Nicsoft
Have you validated your form? // btw you can style `input[type="submit"]:focus` or `button:focus` // also if you have 2 forms you should separate them (perhaps it's a problem with fieldset)
Knu
Yes, the form is validate (now...). The changes I had to make didn't help this problem. Tried your notification for style as well, no difference. I don't know if there is any problem with me having two forms. I close the first one before starting the new and the tabindex (when I used that) wasn't restarted, just continued in the second form. Are you sure it's really possible to get this working for all browsers on all OS. Check my own answer.
Nicsoft
+2  A: 

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
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.
henasraf
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
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.
henasraf
Hehe... Thank you for helping out, the discussion helped me understand what is possible and not.
Nicsoft
Thanks for your test.
Sandra
+1  A: 

Apparently, it's a Firefox 'Feature" on Macs 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

Tom Wuttke
A: 

This is a Mac OS X issue. Your Mac may be configured to not allow you to tab to 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

Rick