I wrote a Javascript to validate a few simple fields on my form. My issue is that the code works even when there are no errors on the form.
Specifically it throws an error at if(openHour > closeHour)
This is the code:
function checkForm()
{
var openHour;
var closeHour;
var i;
for(i=1;i<8;i++)
{
openHour = document.getElementById("openHours" + i).value;
closeHour= document.getElementById("closeHours" + i).value;
if(openHour > closeHour)
{
document.getElementById('error').innerHTML= "Opening Error at " + i;
return false;
}
if(openHour == "0" && closeHour > 0)
{
document.getElementById('error').innerHTML= "Closing Error at " + i;
return false;
}
}
}
I just needed to parse the values to integers in order to be able to compare them.
Thanks all for your help