1
I have the code below that creates three fields in HTML these fields go through the checks below with Javascript, however, the part that should check if the person typed something does not work, I am doing it the right way?
function checadatas(){
var form_ins = document.acess;
console.log(form_ins);
var data1 = new Date(form_ins.inp.value);
var data2 = new Date(form_ins.fip.value);
if (!data1 || !data2){
return false;
}
if (data1 > data2){
alert("Data não pode ser maior que a data final");
return false;
} else {
return true;
}
if(document.acess.inp.value == null){
alert("Digite uma data!");
return(false);
} else if(document.acess.fip.value == null){
alert("Digite uma data!");
return(false);
} else if(document.acess.ver.value == null){
alert("Digite uma data!");
return(false);
} else {
return true;
}
}
<form method="POST" action="#" onSubmit="return checadatas()" name="acess">
<br><br>
<a a class="arib">Data de inicio da verificação: </a><input type="date" name="inp"/>
<a a class="arib">Data de fim da verificação: </a><input type="date" name="fip"/>
<br><br><br>
<a a class="arib">Data ser realizada a verificação: </a><input type="date" name="ver"/>
<br><br><br>
<button class="css_btn_class" type="submit" name="Enviar">Inserir ativo</button>
</form>
because the field has content that may not be
null
, you can compare with empty:document.acess.inp.value == ""
– Ricardo Pontual
I made this exchange, and the program keeps ignoring this part
– Geraldão de Rívia
looks well your code seems to me that it would be correct to put the commands
if
which validate whether it is empty at the beginning of Function. Note that if the field is empty, you may miss this line:var
data1 = new date(form_ins.inp.value);`– Ricardo Pontual