function calcular_edad(dia_nacim,mes_nacim,anio_nacim)
{
fecha_hoy = new Date();
ahora_anio = fecha_hoy.getYear();
ahora_mes = fecha_hoy.getMonth();
ahora_dia = fecha_hoy.getDate();
edad = (ahora_anio + 1900) - anio_nacim;
if ( ahora_mes < (mes_nacim - 1))
{
edad--;
}
if (((mes_nacim - 1) == ahora_mes) && (ahora_dia < dia_nacim))
{
edad--;
}
if (edad > 1900)
{
edad -= 1900;
}
return edad;
}
</script>
---//calcular la edad de una persona
//recibe la fecha como un string en formato espaol
//devuelve un entero con la edad. Devuelve false en caso de que la fecha sea inc
orrecta o mayor que el dia actual
function calcular_edad(fecha){
//calculo la fecha de hoy
hoy=new Date()
//alert(hoy)
//calculo la fecha que recibo
//La descompongo en un array
var array_fecha = fecha.split("/")
//si el array no tiene tres partes, la fecha es incorrecta
if (array_fecha.length!=3)
return false
//compruebo que los ano, mes, dia son correctos
var ano
ano = parseInt(array_fecha[2]);
if (isNaN(ano))
return false
var mes
mes = parseInt(array_fecha[1]);
if (isNaN(mes))
return false
var dia
dia = parseInt(array_fecha[0]);
if (isNaN(dia))
return false
//si el ao de la fecha que recibo solo tiene 2 cifras hay que cambiarlo a 4
if (ano<=99)
ano +=1900
//resto los aos de las dos fechas
edad=hoy.getYear()- ano - 1; //-1 porque no se si ha cumplido aos ya este ao
//si resto los meses y me da menor que 0 entonces no ha cumplido aos. Si da m
ayor si ha cumplido
if (hoy.getMonth() + 1 - mes < 0) //+ 1 porque los meses empiezan en 0
return edad
if (hoy.getMonth() + 1 - mes > 0)
return edad+1
//entonces es que eran iguales. miro los dias
//si resto los dias y me da menor que 0 entonces no ha cumplido aos. Si da ma
yor o igual si ha cumplido
if (hoy.getUTCDate() - dia >= 0)
return edad + 1
return edad
}
/*************************************************************/
// NumeroALetras
// @author Rodolfo Carmona
/*************************************************************/
function Unidades(num){
switch(num)
{
case 1: return
case 2: return
case 3: return
case 4: return
case 5: return
case 6: return
case 7: return
case 8: return
case 9: return
}
"UN";
"DOS";
"TRES";
"CUATRO";
"CINCO";
"SEIS";
"SIETE";
"OCHO";
"NUEVE";
return "";
}
function Decenas(num){
decena = Math.floor(num/10);
unidad = num - (decena * 10);
switch(decena)
{
case 1:
switch(unidad)
{
case 0: return "DIEZ";
case 1: return "ONCE";
case 2: return "DOCE";
if (cientos > 1)
letras = Centenas(cientos) + " " + strPlural;
else
letras = strSingular;
if (resto > 0)
letras += "";
return letras;
}//Seccion()
function Miles(num){
divisor = 1000;
cientos = Math.floor(num / divisor)
resto = num - (cientos * divisor)
strMiles = Seccion(num, divisor, "UN MIL", "MIL");
strCentenas = Centenas(resto);
if(strMiles == "")
return strCentenas;
return strMiles + " " + strCentenas;
//return Seccion(num, divisor, "UN MIL", "MIL") + " " + Centenas(resto);
}//Miles()
function Millones(num){
divisor = 1000000;
cientos = Math.floor(num / divisor)
resto = num - (cientos * divisor)
strMillones = Seccion(num, divisor, "UN MILLON", "MILLONES");
strMiles = Miles(resto);
if(strMillones == "")
return strMiles;
return strMillones + " " + strMiles;
//return Seccion(num, divisor, "UN MILLON", "MILLONES") + " " + Miles(resto);
}//Millones()
function NumeroALetras(num){
var data = {
numero: num,
enteros: Math.floor(num),
centavos: (((Math.round(num * 100)) - (Math.floor(num) * 100))),
letrasCentavos: "",
letrasMonedaPlural: "CORDOBAS",
letrasMonedaSingular: "CORDOBA"
};
if (data.centavos > 0)
data.letrasCentavos = "CON " + data.centavos + "/100";
if(data.enteros == 0)
return "CERO " + data.letrasMonedaPlural + " " + data.letrasCentavos;
if (data.enteros == 1)
return Millones(data.enteros) + " " + data.letrasMonedaSingular + " " + data
.letrasCentavos;
else
return Millones(data.enteros) + " " + data.letrasMonedaPlural + " " + data.l
etrasCentavos;
}//NumeroALetras()
-----<!doctype html>
<html>
<head>
<title>Numero a letras</title>
<script type="text/javascript">
// Convert numbers to words
// copyright 25th July 2006, by Stephen Chapman http://javascript.about.
com
// permission to use this Javascript on your web page is granted
// provided that all of the code (including this copyright notice) is
// used exactly as shown (you can change the numbering system if you wis
h)
// American Numbering System
var th = ['','thousand','million', 'billion','trillion'];
// uncomment this line for English Number System
// var th = ['','thousand','million', 'milliard','billion'];
var dg = ['zero','one','two','three','four', 'five','six','seven','eight
','nine'];
var tn = ['ten','eleven','twelve','thirteen', 'fourteen','fifteen','sixt
een', 'seventeen','eighteen','nineteen'];
var tw = ['twenty','thirty','forty','fifty', 'sixty','seventy','eighty',
'ninety'];
function toWords(s){s = s.toString(); s = s.replace(/[\, ]/g,''); if (s
!= parseFloat(s)) return 'not a number'; var x = s.indexOf('.'); if (x == -1) x
= s.length; if (x > 15) return 'too big'; var n = s.split(''); var str = ''; var
sk = 0; for (var i=0; i < x; i++) {if ((x-i)%3==2) {if (n[i] == '1') {str += tn
[Number(n[i+1])] + ' '; i++; sk=1;} else if (n[i]!=0) {str += tw[n[i]-2] + ' ';s
k=1;}} else if (n[i]!=0) {str += dg[n[i]] +' '; if ((x-i)%3==0) str += 'hundred
';sk=1;} if ((x-i)%3==1) {if (sk) str += th[(x-i-1)/3] + ' ';sk=0;}} if (x != s.
length) {var y = s.length; str += 'point '; for (var i=x+1; i<y; i++) str += dg[
n[i]] +' ';} return str.replace(/\s+/g,' ');}
</script>
<script type="text/javascript">
function mostrarNumero(elem){
var texto = toWords(elem.value);
document.getElementById('mostrarAca').innerHTML = texto;
}
</script>
</head>
<body>
<input type="text" onkeyup="mostrarNumero(this)" />
<p id="mostrarAca"></p>
</body>
</html>
---<html>
<script>
}
window.onload=st;
</script>
<body>
<!--numero: <input id="num"><input type="button" value="C" onclick="nn(document.
getElementById('num').value);"><br>
escrito: <input style="width: 40em;" id="esc">-->
<div id="out"></div>
</body>
</html>