I am absolutely new in JavaScript development and I have to perform the following task: I have 2 input tag containing 2 string representing date in the form 01/12/2014 (DAY/MONTH/YEAR). I use this input tag to search objects that have a date field that is among these dates.
<input type="hidden" size="9" class="impPrfTot" readonly="readonly"
onchange="cambioDataDa(this.value)"
name="dataDa" id="datada" value="<%=request.getSession().getAttribute("dataDa")%>"
style="font-size: 11px;color: #000000;">
<input type="hidden" size="9" class="impPrfTot" readonly="readonly"
onchange="cambioDataA(this.value); checkData(this.value)"
name="dataA" id="dataa" value="<%=request.getSession().getAttribute("dataA")%>"
style="font-size: 11px;color: #000000;">
<button class="dataDadataAButton" name="submitdataDadataA" onclick="sottomettiFormDataDaA(this)">Cerca</button>
And finally I have a button used to submit this form using this JavaScript:
function sottomettiFormDataDaA(obj) {
document.getElementById('dataDaAForm').submit();
}
What I need is to prevent that the value inside dataA (in English language dateTo) input is previous that dataDa value (in English language dateFrom).
I am trying to do something like this:
The JavaScript is called at the onchange event on the change of a data and take the dataA string (tha represent the dateTo date) and check if it is previous of the dataA (the dateTo date).
If the previous check is true the date range is invalid so the script show an error popup message and disallow the submit of the form having id="dataDaAForm"
function checkData(dataA) { dataDa = document.getElementById('dataDa').value; if(dataDa > dataA){ // SHOW A POPUP ERROR MESSAGE // DISALLOW THE FORM SUBMIT } }
Bue I have really not idea about complete this JavaScript and I don't know it exist better solution to achieve this task.