hola, tengo una funcion ( y si hay una mejor, agradeceria que me la pasasen xD) que quiero que si el usuario no entro un numero regrese el foco.
Código HTML:
Ver original<!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"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript"> function formatNumber(v) {
var num = new Number(v.value);
if(isNaN(num) || num=='Infinity') {
v.value = '';
v.focus(); //he probado esto y tmb this.focus(); y no funciona, el foco nunca ocurre
} else {
v.value = num.toFixed(2);
}
}
<input type="text" onblur="formatNumber(this)" />
Ahora que checo, no funciona en firefox nada mas, en IE si