Results 1 to 3 of 3

Thread: How to find out which element has focus?

  1. #1
    Join Date
    Aug 2008
    Location
    Western Europe
    Posts
    17
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default How to find out which element has focus?

    Is there a quick way to find out which element has focus?

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    HTML Code:
    <script type="text/javascript"> 
    var elName; 
    window.onload=function()
    { 
    var el = document.forms[0].elements; 
    for(var i=0;i<el.length;i++)
    	el[i].onfocus=function()
    	{
    		elName=this.getAttribute('name');
    	} 
    } 
    </script> 
    </head> 
    <form>
    <a href="#" onclick="alert(elName?'The element having the name of \''+elName+'\' was focused.':'No element was focused.'); return false">"Which element has the focus?"</a><br> 
    <input name="mytxt1" type="text"><br> 
    <input name="mytxt2" type="text"><br> 
    <input name="mytxt3" type="text"><br>
    <input name="mytxt4" type="text"><br> 
    <input name="mytxt5" type="text"><br> 
    </form>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. The Following User Says Thank You to rangana For This Useful Post:

    Tohaki (10-30-2008)

  4. #3
    Join Date
    Aug 2008
    Location
    Western Europe
    Posts
    17
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Thanks!

Bookmarks

Posting Permissions

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