Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting input control focus without javascript [duplicate]

Tags:

html

Is there a way to set the focus in a specific HTML input (a textarea control, actually), without using Javascript?

EDIT: Is possible in HTML5 but the question is about HTML < 5

like image 301
GClaramunt Avatar asked Jun 11 '09 19:06

GClaramunt


People also ask

How do you set focus on input field?

To set focus to an HTML form element, the focus() method of JavaScript can be used. To do so, call this method on an object of the element that is to be focused, as shown in the example. Example 1: The focus() method is set to the input tag when user clicks on Focus button.

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.


2 Answers

You can use autofocus in HTML5 documents, but it has little support at present (see chart).

like image 80
Tgr Avatar answered Nov 15 '22 20:11

Tgr


Nope. Sadly JavaScript is required, because it's dynamically modifying the browser on the client-side (what JavaScript was made for).

like image 30
Andrew Dunkman Avatar answered Nov 15 '22 21:11

Andrew Dunkman