Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 autofocus = autoselect?

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?

like image 936
Fer Avatar asked Jan 19 '11 20:01

Fer


People also ask

How do I autofocus a div in HTML?

The autofocus attribute is a boolean attribute. When present, it specifies that the element should automatically get focus when the page loads.

Does autofocus attribute always set focus on first input field in html5?

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.

What does html5 autofocus attribute do when applied to the HTML select element?

The autofocus attribute is a boolean attribute. When present, it specifies that the drop-down list should automatically get focus when the page loads.


1 Answers

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.

like image 168
Pascal_dher Avatar answered Sep 22 '22 03:09

Pascal_dher