Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts

    onFocus eventListener for all Textareas

    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.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Call this onload.
    Code:
    function setEvent(){
      var tas = document.getElementsByTagName('textarea');
      var len = tas.length;
      for (var i=0; i<len; i++){
         tas[i].onfocus = function(){this.select();};
      }
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •