1
I need to check if the user entered the date in two date fields.
<input type="text" name="data1"/>
<input type="text" name="data2"/>
How do we fix this? If I put required in the field, it only works on Chrome. But and pro Firefox and Safari?
See @Renaro Santos
<script>
function validar(){
var data1= document.getElementById("dataInicio").value;
var data2= document.getElementById("dataFim").value;
if(data1 == "" || data2=""){
alert('Uma das datas esta vazia');
return false;
}
}
</script>
<form method="post" action="" onsubmit="validar()">
Data inicial<input type="text" id="dataInicio" name="dataInicio" required>
Data Final<input type="text" id="dataFim" name="dataFim" required>
<input type="submit" name="pesquisar" value="Pesquisar">
</form>
the input of the kind date has not yet been implemented in all browsers so its use is not recommended, take a look at this jQuery plugin for validation: http://formvalidator.net/
– Pedro Sanção
Sorry, I’m actually using type="text" and not date.
– GustavoSevero