
Ayuda con input date html5 javascript, calcular edad
Publicado por Erasmo (5 intervenciones) el 20/05/2013 19:47:06
Tengo esta función:
El siguiente formulario con los input:
La cuestion es que el campo edad no recoge el valor que genera la funcion, ya estoy enredado con javascript DOM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<script language="JavaScript">
function calcular_edad(fecha){
var selectObject = document.forms['alumno'].elements['fechan'];
var fecha = selectObject.options[selectObject.selectedIndex].value;
hoy=new Date()
var array_fecha = fecha.split("/")
if (array_fecha.length!=3)
return false
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
if (ano<=99)
ano +=1900
edad=hoy.getYear()- ano - 1; //-1 porque no se si ha cumplido años ya este año
if (hoy.getMonth() + 1 - mes < 0) //+ 1 porque los meses empiezan en 0
return edad
if (hoy.getMonth() + 1 - mes > 0)
return edad+1
if (hoy.getUTCDate() - dia >= 0)
return edad + 1
document.getElementsByName(edad).value = edad
}
</script>
El siguiente formulario con los input:
1
2
3
4
<form method="post" id="alumno">
<input name="fechan" type="date" id="fechan" tabindex="6" onblur="calcular_edad(this.value)"/>
<input name="edad" type="text" readonly="readonly" style="text-align:center" required="required" id="edad" tabindex="7" size="3" />
</form>
La cuestion es que el campo edad no recoge el valor que genera la funcion, ya estoy enredado con javascript DOM
Valora esta pregunta


0