Solved

javascript - set focus on particular control

Posted on 2011-02-18
4
463 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
  • 3
4 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 34927608
document.getElementById("textarea1").focus();
0
 
LVL 51

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

785 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