function validarData(){
var data = document.getElementById("nasc");
if(data.value == ''){
alert("Data não preenchida!");
return;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Da11a2 Exemplo</title>
</head>
<body>
<label for="nasc">Data de nascimento:</label>
<input type="date" id="nasc" name="nasc" min= "1990-12-30"max="2001-12-30" />
<button onClick="validarData()"> Enviar </button>
</body>
</html>
You can do this validation by clicking the desired button to send your form
, in this case the Send button.
I made a simple example where a validation is made if the field has not been filled in, in this case an alert is invoked.
<!DOCTYPE html>
<html>
<head>
<title>Da11a2 Exemplo</title>
<script>
function validarData(){
var data = document.getElementById("nasc");
if(data.value == ''){
alert("Data não preenchida!");
return;
}
}
</script>
</head>
<body>
<label for="nasc">Data de nascimento:</label>
<input type="date" id="nasc" name="nasc" min= "1990-12-30"max="2001-12-30" />
<button onClick="validarData()"> Enviar </button>
</body>
</html>
You do not want to allow to advance at the click of a button?
– RXSD
I want that when the person presses send and that field has not been filled in should still appear an Alert saying that there is an error.
– Da11a2
Try to run my example or the Leandrade and see which one adapts to your need. The difference is the call of JS for the validation.
– RXSD