De alex55 - le 25-04-2006 Le script n'est pas compatible avec IE v.6 contrairement à ce qui est dit. Cela génère une erreur de script. Par contre, il marche sous Mozilla. | De Inform - le 11-03-2007 bien d'accord avec alex55 | De kiki67100 - le 15-04-2008 J'ai un peut modifier le code il marche sous IE on peut simplifier le code je posterais une new code meilleur pour l'instant :)
le code :
<html>
<head>
<style>
form{
width:30%;
background-color:orange;
border:1px solid black;
}
form p{
font-size:1em;
font-weight:bold;
margin-top:0px;
}
input {
background-color:white;
border:1px solid black;
color:black;
}
</style>
<script>
function calc_age()
{
actu=new Date();
day=parseInt(document.getElementById('jour').value);
mounth=parseInt(document.getElementById('mois').value);
year=parseInt(document.getElementById('annee').value);
if((actu.getMonth()+1)>=mounth)
{
if((actu.getMonth()+1)==mounth)
{
if(actu.getDate()>=day)
{
mois=(actu.getMonth()+1)-mounth;
ans=actu.getFullYear()-year;
}
else
{
mois=(12-mounth)+(actu.getMonth()+1);
ans=actu.getFullYear()-year-1;
}
}
else
{
mois=(actu.getMonth()+1)-mounth;
ans=actu.getFullYear()-year;
}
}
else
{
mois=(12-mounth)+(actu.getMonth()+1);
ans=actu.getFullYear()-year-1;
}
if(actu.getDate()>day)
{
jours=actu.getDate()-day;
}
else
{
jours=(30-day)+(actu.getDate());
}
while(jours>30)
{
jours-=30;
mois+=1;
}
while(mois>12)
{
mois-=12;
ans+=1;
}
return ans;
}
function show_result()
{
out=document.getElementById('result');
out.innerHTML='<p>Vous avez :'+calc_age()+' ans</p>';
}
</script>
</head>
<body>
<form>
<p style="text-align:center; background-color:white; width:100%;">Calculer votre age ...</p>
<table>
<tr>
<td>Jour(jj) :</td><td><input maxlength="2" type="text" id="jour"></td></tr><tr>
<td>Mois(mm) :</td><td><input maxlength="2" type="text" id="mois"></td></tr><tr>
<td>Année(aaaa) :</td><td><input maxlength="4" type="text" id="annee"></td></tr><tr>
<td></td><td><input type="button" value="Calculer" onclick="show_result();"></td>
</tr>
</table>
<div style="text-align:center;" id="result"></div>
</form>
</body>
</html> |