Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/
function InputHighLight(id,type,col,cls){
var obj=document.getElementById(id)||document;
var ips=obj.getElementsByTagName('INPUT');
this.ary=[];
for (var z0=0;z0<ips.length;z0++){
if (ips[z0].type==type&&(!cls||(!ips[z0].className||ips[z0].className!=cls))){
this.addevt(ips[z0],'blur','HighLight');
this.ary.push(ips[z0]);
}
}
this.col=col||'red';
}
InputHighLight.prototype.HighLight=function(){
for (var ip,z0=0;z0<this.ary.length;z0++){
ip=this.ary[z0];
ip.style.backgroundColor=ip.value.replace(/\s/g,'')!=''?this.col:'transparent';
}
}
InputHighLight.prototype.addevt=function(o,t,f,p){
var oop=this;
if (o.addEventListener) o.addEventListener(t,function(e){ return oop[f](e,p);}, false);
else if (o.attachEvent) o.attachEvent('on'+t,function(e){ return oop[f](e,p); });
else {
var prev=o['on'+t];
if (prev) o['on'+t]=function(e){ prev(e); oop[f](e,p); };
else o['on'+t]=o[f];
}
}
/*]]>*/
</script></head>
<body onload="IP=new InputHighLight(null,'text','red','no');">
<input class="no" name="" />
<input name="" />
<input type="button" name="" value="TEST" onclick="IP.HighLight();" />
</body>
</html>
Bookmarks