Setting focus in tab change
New DiscussionI want to be able to set the focus to the first field whenever the user switches tabe – i.e. clicks on a new existing tab. I’ve tried different things but nothing seems to work. The last thing I did was attach the following script to the ActiveTabChange event:
function tabInquiry_ActiveTabChange(webTab, currentTab) {
var textbox = null;
var tabs = webTab.get_tabs();
switch (currentTab.get_tabIndex())
{
case 0:
textbox = document.getElementById(GetClientId(‘txtKey1’));
break;
case 1:
var textbox = null;
textbox = document.getElementById(GetClientId(‘txtKey2’));
break;
case 2:
var textbox = null;
textbox = document.getElementById(GetClientId(‘txtKey3’));
break;
case 3:
var textbox = null;
textbox = document.getElementById(GetClientId(‘txtKey4’));
break;
default:
break;
}
if (textbox != null) {
textbox.select();
textbox.setActive();
try {
textbox.focus();
}
catch (err) {
}
textbox.click();
}
}
The weird thing is that when I change tabs, the ActiveTabChange event gets invoked four times. I assume it is getting activated during the deactivation of the current tab and the activation of the new tab. There doesn’t seem to be a way to determine which event is being processed from the parameters that I can see.
There is a sore lack of documentation or info on this particular event and/or the parameters it uses. So what can I use/do during the activation of a new tab to set the focus to whatever field I want on that tab’s content page?
P.S. The reason I have the textbox.focus() in a try…catch block is that it never seems to work – always gives an error message.
Any help/code appreciated. Thanks.
/Tom