Monday, March 2, 2009

Alternative method for attaching javascript event handlers to a text box for IE6 compatibility

Attaching event handlers OnFocus and OnBlur work ok under IE6/IE7, and FireFox if its done this this way:

txtSearchText.Attributes.Add("onfocus","ClearTextBox()"); txtSearchText.Attributes.Add("onblur", "RepopulateTextBox()");

BUT this way does not work under IE6:

control.onfocus = function() { ClearTextBox(); }
control.onblur = function() { RepopulateTextBox(); }

No comments: