[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

javascript - set focus on particular control

Posted on 2011-02-18
4
Medium Priority
?
477 Views
Last Modified: 2012-05-11
I have 5 textarea...and I need to control which one has focue...how is that done?

    <TEXTAREA onKeyUp="javascript:countChars();" id=textarea1 name=textarea1 rows=7 cols=43></TEXTAREA><br />
      No. of characters:&nbsp; <INPUT id=text1 name=text1 style="borderWidth:0;border:none;" size=5 value=0 readonly>
      <BR> <BR>
0
Comment
Question by:GlobaLevel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 2000 total points
ID: 34927608
document.getElementById("textarea1").focus();
0
 
LVL 60

Expert Comment

by:HainKurt
ID: 34927668
"javascript:countChars(this);"

and add a param to the js function

function countChars(ta){
... use ta, it will give you which textarea you are working with...
}
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34927711
if you want to know which one has focus, then add the following javascript at body onload event

var latestTextArea;
document.getElementsByTagName("textarea").onkeyup = function(this){
  latestTextArea = this.getAttribute("id");
};

0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34927729
now when ever you will press a key, 'latestTextArea' will be updated with the id of the latest TextArea

you can also do the same on the onfocus event (just replace onkeyup with onfocus)

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question