I'm learning Javascript and I'm making a retirement calculator. I would like to know how to get the two dates entered in the html form and calculate the difference between them and give the difference as output.
I have the following html
<form name="aposentadoria">
<fieldset>
<legend>Sexo</legend>
<input type="radio" name="sexo" value="M" /><i class="fa fa-male"></i>Masculino:<br />
<input type="radio" name="sexo" value="F" /><i class="fa fa-female"></i>Feminino<br />
</fieldset>
<select name="regra">
<option value="25">25 anos</option>
<option value="20">20 anos</option>
<option value="15">15 anos</option>
</select>
<label for="empresa">Empresa</label>
<input type="text" name="empresa" placeholder="Empresa: ">
<label for="dataAdm">Admissão</label>
<input type="date" name="dataAdmissao" placeholder="Admissão: ">
<label for="dataDem">Demissão</label>
<input type="date" name="dataDemissao" placeholder="Demissão: ">
<input type="button" value="Calcular" onclick="calcula()" >
And JavaScript
function calcula(){
var sexo = document.aposentadoria.sexo.value;
var regra = document.aposentadoria.regra.value;
var empresa = document.aposentadoria.empresa.value;
var dataAdmissao = document.aposentadoria.dataAdmissao.value;
var dataDemissao = document.aposentadoria.dataDemissao.value;
var anosAjus = "Você trabalhou " + "anos nas empresas " +empresa+ " sob a regra de " +regra;
alert(anosAjus);
}
Could you help me with this calculation?