0
I have a form with the fields below. I need to compare the year of the field select
with year of date informed via Javascript, and the year of date informed has to be identical to the year chosen, but I have not yet succeeded.
<label for="ano_licenca"><strong>ANO DA LICENCA</strong></label>
<select name="ano_licenca" id="ano_licenca" class="form-control">
<option value="">SELECIONE</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
</select> <br><br>
<label for="data_emissao"><strong>DATA EMISSAO *</strong></label>
<input type="date" name="data_emissao" id="data_emissao" class="form-control" onblur="comparadataano()" autofocus/><br><br/>
<script type="text/javascript">
function comparadataano()
{
var ano_licenca = document.getElementById("ano_licenca");
var data_emissao = document.getElementById("data_emissao");
if (data_emissao.value > ano_licenca.value || data_emissao.value < ano_licenca.value) {
alert("ERRO! O ANO INFORMADO, NAO ESTAR COM O MESMO ANO DA DATA DE EMISSAO");
ano_licenca = document.getElementById('ano_licenca').value = '';
data_emissao = document.getElementById('data_emissao').value = '';
}
}
</script>
Thanks friend! Thanks for the strength
– odmarques