To set the variable txtBoxWithFocus:
- var txtBoxWithFocus = name;
Then to select:
- document.getElementById(txtBoxWithFocus).select()
though to be honest I don't know why you want to do it like that, unless I've misunderstood.
I've created a control that lets you control time with buttons.
It lets you set a time period.
-
Start Time: [textboxHrs][textboxMinutes]{buttons up and down}
-
End Time: [textboxHrs][textboxMinutes]{buttons up and down}
-
I had to control either the textboxHrs or the textboxMinutes when the user clicked the up or down button. (This is why I had to store the name of the text box, because the text box's focus is lost when the user clicks the button)
The problem was that the user couldn't really tell which text box the button was going to change.
Also the user couldn't just click on the text box and enter a time because of the max length restrictions.
So I've written a little code that selects the text box's contents and stores the name of that text box (to indicate to the button that it should be changed) when it has focus...
I reselected the text when the user clicked the buttons to make sure the user knew which text box was being changed.
Its really a cute little control.
They are added to the web page dynamically through a .NET application.
I'm sure there's an easier way to solve this problem, but I'm very new to JavaScript so I have to do things the hard way first.
Now that its working perfectly I'd love to show it off...but I can't post all the code here.
-LilOlMe