You are on page 1of 2

// creates a function to set the css class name of input controls when they // receive or lose focus.

setAspnetTextFocus = function() { // CSS class name to use when no focus is on the input control var classBlur = 'input_text'; // CSS class name to use when the input control has focus var classFocus = 'input_text_focus'; // get all of the input tags on the page var inputElements = document.getElementsByTagName('search');

for (var i = 0; i < inputElements.length; i++) { // add the onfocus event and set it to add the on focused CSS class inputElements[i].onfocus = function() { if (this.className == 'input_text') { this.className += ' ' + classFocus; } } // add the onblur event and set it to remove the on focused CSS class w hen it loses focus inputElements[i].onblur = function() { this.className = this.className.replace(new RegExp(' ' + classFocus + '\\b'), ''); } } } // attach this event on load of the page if (window.attachEvent) window.attachEvent('onload', setAspnetTextFocus);

/* This is the CSS class to use when no focus is on the input control */ .input_text { border:1px solid #c0c0c0; padding:4px; font-size:14px; color:#000000; background-color:#ffffff; } /* This is the CSS class to use when the control has focus */ .input_text:focus, input.input_text_focus { border-color:#646464; background-color:#ffffc0; }

You might also like