Question:
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?
Answer:
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.