Fijate si te sirve:
Código PHP:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test</title>
<style>
.input_rojo{border:1px solid red;}
</style>
<script type="text/javascript">
/* ---- credits: Dustin Díaz ---- */
function getElementsByClass(searchClass,node,tag) {
var classElements = new Array();
if ( node == null )
node = document;
if ( tag == null )
tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
}
function addEvent(o,t,f){
if(o.addEventListener){
o.addEventListener(t,f,false);
}else if(o.attachEvent){
var fn=function(){
f.call(o,window.event);
}
o.attachEvent('on'+t,fn);
}else
throw 'No se puede asignar el evento.';
}
var laFuncion=function(){alert(this.name);}
onload=function(){
var col=getElementsByClass('input_rojo',null,'input');
for(var i in col){
addEvent(col[i],'focus',laFuncion);
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<input class="input_rojo" type="text" name="textfield" />
<input type="text" name="textfield2" />
<input class="input_rojo" type="text" name="textfield3" />
<input type="text" name="textfield4" />
<input class="input_rojo" type="submit" name="Submit" value="Enviar" />
</form>
</body>
</html>