I need a simple comparison between dates in javascript so the end date can not be less than the start date. I found some scripts on the internet and tried to adapt to mine, but as I know practically nothing, it did not work.
Follow the script I'm adapting.
<script language="javascript">
function checarDatas(){
var form_insere = document.form_insere;
var data_1 = form_insere.datainicial.value;
var data_2 = form_insere.datafinal.value;
var Compara01 = parseInt(data_1.split("/")[2].toString() + data_1.split("/")[1].toString() + data_1.split("/")[0].toString());
var Compara02 = parseInt(data_2.split("/")[2].toString() + data_2.split("/")[1].toString() + data_2.split("/")[0].toString());
if (Compara01 > Compara02) {
alert("Data não pode ser maior que a data final");
return false;
}
else {
return true
}
}
</script>
I also put onsubmit="return checarDatas()"
in the form tag.
The goal is when the user enters a start date (05/07/2014) and then the end date (04/06/2014) triggers an alert indicating that the dates are wrong and do not let him submit the form until he returns and corrects.
Thanks, and I accept any kind of suggestions.