
22/02/2006, 17:25
|
| | Fecha de Ingreso: mayo-2005
Mensajes: 63
Antigüedad: 19 años, 10 meses Puntos: 1 | |
Hola ya termine el edit mask ojala y le sirva a alguien, despues de muchas horas de esfuerzo, le hice modificaciones al anterior, le agrege una funcion de validacion de numeros, separador de miles, y una funcion para seleccionar el texto para hacer mas facil el manejo.. espero les guste
<html>
<head>
<style type="text/css">
<!--
.in-medio {
margin-right: 0px;
margin-left: 0px;
border-top-width: thin;
border-bottom-width: thin;
border-top-style: solid;
border-right-style: none;
border-bottom-style: solid;
border-left-style: none;
border-top-color: #000000;
border-bottom-color: #000000;
text-align: right;
}
.in-dcha {
margin-top: auto;
margin-right: 0px;
margin-bottom: auto;
margin-left: 0px;
border-top-width: thin;
border-right-width: thin;
border-bottom-width: thin;
border-left-width: thin;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: none;
border-top-color: #000000;
border-right-color: #000000;
border-bottom-color: #000000;
border-left-color: #000000;
text-align: left;
}
.in-izq {
margin-top: auto;
margin-right: 0px;
margin-bottom: auto;
margin-left: 0px;
border-top-width: thin;
border-right-width: thin;
border-bottom-width: thin;
border-left-width: thin;
border-top-style: solid;
border-right-style: none;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #000000;
border-right-color: #000000;
border-bottom-color: #000000;
border-left-color: #000000;
}
-->
</style>
<script language="JavaScript">
function punto(e,txt_dec)
{
tecla=event.keyCode
if(tecla==46)
{
txt_dec.focus()
return false
}
else
{
return true;
}
}
function validaciones(variable,dec_numero,ent_numero)
{
if ((variable>=48 && variable<=57) || variable==8 || variable==46 || variable==44)
{
if (variable==8 && dec_numero.value=="")
{
ent_numero.focus()
dec_numero.value='00'
}
else if (variable==8 && ent_numero.value=="")
{ ent_numero.value=0
textboxSelect(ent_numero)
}
else if (variable==8)
separar_miles(ent_numero)
}
else
{
event.keyCode=0
}
}
function separar_miles(cantidad)
{
valor=String(cantidad.value)
longitud=valor.length
var arreglo= new Array()
contador=0;
for (i=0;i<longitud; i++)
{
if (valor.charAt(i)!=',')
{
arreglo[contador]=valor.charAt(i)
contador++;
}
}
var cad1="",cad2="",cont=0;
for (j=arreglo.length-1;j>=0;j--)
{
cad1=arreglo[j]
cad2=cad1+cad2
cont++;
if ((cont % 3)==0)
{
if (j!=0)
{
cad2=','+ cad2
}
}
}
cantidad.value=cad2
}
function textboxSelect(oTextbox)
{
var oRange = oTextbox.createTextRange();
oRange.moveStart("character", 0);
oRange.moveEnd("character", oTextbox.value.length-1);
oRange.select();
}
</script>
</head>
<body>
<form name="formulario">
<input name="moneda" type="text" class="in-izq" value="$" size="1" style="width:9px" readonly tabIndex=-1>
<input name="enteros" type="text" class="in-medio" onkeypress="validaciones(event.keyCode, decimales, enteros);return punto(event,decimales)" size="15" maxlength="15" value="0" onfocus="textboxSelect(this)" onkeyup="separar_miles(this)">
<input name="p" type="text" class="in-medio" style="width:3px;" size="1" value="." readonly tabIndex=-1>
<input name="decimales" type="text" id="decimales" class="in-dcha" onfocus="(enteros.value=='')?enteros.focus():textb oxSelect(this)" size="2" maxlength="2" onkeypress="validaciones(event.keyCode,this,entero s)" value="00">
</form>
</body>
</html> |