Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: JavaScript
Expertise: Beginner
Jul 9, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Manipulate the Last Active Textbox

I want to use a form that contains a set of textboxes and a set of buttons. When I push a button, I want to manipulate the last active textbox. I tried using ActiveElement, but I got the focus of the button and not the textbox. Can I use a global variable to set the number of the last active textbox?

One way to get the effect you're looking for is to use a global variable to store a reference to the last text box accessed by the user. The saveCtrl() function in the code provided updates the value of this global variable and should be called from a textbox's onFocus event handler. By passing the "this" value to the saveCtrl() function, you're guaranteed that the code will work even if the names of the HTML controls change. When the user clicks the button, you can call the setCtrl() function to automatically change the value of the last accessed textbox. This code also works for other types of HTML controls and is not just limited to textboxes.






DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date