I'm using some HTML5 form features to progressively enhance the user experience of my web project. One in particular is autofocus, I'm wanting to use this in a modal (lightbox) dialog that allows users to enter tags. Existing tags could be there.
The only browser I have installed that supports autofocus is Chrome 9, however when I test it there it does place the focus on the field, but also automatically selects all existing text in the field. I did not expect or want autoselect, I want autofocus.
Is my expectation wrong or is Chrome wrong?
The autofocus attribute is a boolean attribute. When present, it specifies that the element should automatically get focus when the page loads.
The first input or textarea in source order that has the autofocus attribute will be focused on page load. In browsers without autofocus support, no fields will be focused on page load, unless otherwise given focus with JavaScript.
The autofocus attribute is a boolean attribute. When present, it specifies that the drop-down list should automatically get focus when the page loads.
Chrome decided they were wrong and changed this behaviour in Chrome 36.
I know this because I was wrongly relying on javascript .focus() and html autofocus for also selecting the text. Now it requires a .select() to select and focus in the text field. Good that we can now be specific of what we want :-)
So now Chrome behaves like e.g. Firefox.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With