?
Solved

javascript - set focus on particular control

Posted on 2011-02-18
4
Medium Priority
?
475 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:
gurvinder372 earned 2000 total points
ID: 34927608
document.getElementById("textarea1").focus();
0
 
LVL 57

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:gurvinder372
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:gurvinder372
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 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