Solved

javascript - set focus on particular control

Posted on 2011-02-18
4
469 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 500 total points
ID: 34927608
document.getElementById("textarea1").focus();
0
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

726 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