View Full Version : onFocus eventListener for all Textareas

07-01-2005, 12:45 AM
Is it possible to add an eventListener of onFocus for every textarea in a page without declaring it for each? For example, let's say that when any textarea is put into focus, all of the text in it is selected.

07-01-2005, 03:37 AM
Call this onload.

function setEvent(){
var tas = document.getElementsByTagName('textarea');
var len = tas.length;
for (var i=0; i<len; i++){
tas[i].onfocus = function(){this.select();};