Accessibility - Default html form focus without JavaScript

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

Is it possible to set the default input focus on an HTML form without using JavaScript, for example:

<html>
  <form>
    Input 1: <input type="text" name="textbox1"/>
    <br/>
    Input 2: <input type="text" name="textbox2"/>
  </form>
</html>

I want to set the default focus to either of the text-boxes when the form loads without using JavaScript (as I want the behaviour to occur when a user has js disabled).

Answers

You can do it in HTML5, but otherwise, you must use JavaScript.

HTML5 allows you to add autofocus to your form element, eg:

<input type="text" name="myInput" autofocus />

This does work in browsers which support HTML5 (Or rather, browsers which support this particular part of HTML5) but as you know, not everybody can use it yet.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/4166423/default-html-form-focus-without-javascript

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils