I have the following code in the OnChange() event for a field.
alert("alert text");
crmForm.all.fieldname.SetFocus();
The page acts like the SetFocus call isn’t even there.
Anyone know why this is?
EDIT: I’ve also tried the following to no avail.
crmForm.all.fieldname.Focus();
crmForm.all.fieldname.focus();
alert("alert text", function() { crmForm.all.fieldname.SetFocus()});
Turns out that retaining focus on the field from which the OnChange() method was called is broken in CRM 4 without the most recent rollup. This is a known issue with a Microsoft KB article.
To achieve the illusion of retaining focus on the field simply set the focus to a different field on the same tab first and then reassign the focus to the field from which the OnChange() event was called like so: