I have a form for registering some bookings. The problem is that I want to validate the data users enter in this form. All works fine, excepting the booking hours (ready by and closing time).
This is the part of the script that does not work:
[CODE=javascript]
function validate_fields ()
{
if (document.getEl ementById("comp ania").value.le ngth == "0")
{
document.getEle mentById("compa nia").style.bac kground = "#FD9B80";
submitOK="false ";
}
...............
var data = new String(document .getElementById ("data").value) ;
var month = data[3]+data[4];
var day = data[0]+data[1];
var year = data[6]+data[7]+data[8]+data[9];
var ready_h = document.getEle mentById("ready _h").value;
var ready_m = document.getEle mentById("ready _m").value;
var close_h = document.getEle mentById("close _h").value;
var close_m = document.getEle mentById("close _m").value;
var date_hour_ready = new Date(month + "/" + day + "/" + year + " " + ready_h + ":" + ready_m);
var date_hour_close = new Date(month + "/" + day + "/" + year + " " + close_h + ":" + close_m);
var last_booking_ho ur = new Date (month + "/" + day + "/" + year + " " + "19:00");
var first_booking_h our = new Date (month + "/" + day + "/" + year + " " + "09:00");
var current_date = new Date();
if (isNaN(ready_h) )
{
document.getEle mentById("ready _h").style.back ground = "#FD9B80";
submitOK="false ";
}
...............
if ((data_ora_clos e - data_ora_ready) < 2*60*60*1000)
{
document.getEle mentById("ready _h").style.back ground = "#FD9B80";
document.getEle mentById("ready _m").style.back ground = "#FD9B80";
document.getEle mentById("close _h").style.back ground = "#FD9B80";
document.getEle mentById("close _m").style.back ground = "#FD9B80";
alert("Pickup time should be at least 2 hours.");
submitOK="false ";
}
if (data_ora_ready <= current_date)
{
document.getEle mentById("ready _h").style.back ground = "#FD9B80";
document.getEle mentById("ready _m").style.back ground = "#FD9B80";
//alert("Ready by < closing time");
submitOK="false ";
}
if (data_ora_close > last_booking_ho ur)
{
document.getEle mentById("close _h").style.back ground = "#FD9B80";
document.getEle mentById("close _m").style.back ground = "#FD9B80";
alert("Last pickup time should be 19:00");
submitOK="false ";
}
if (data_ora_ready < first_booking_h our)
{
document.getEle mentById("ready _h").style.back ground = "#FD9B80";
document.getEle mentById("ready _m").style.back ground = "#FD9B80";
alert("You cannot register bookings earlier than 09:00");
submitOK="false ";
}
if (submitOK=="fal se")
{
return false;
}
}
[/CODE]
There are a lot of other ifs in that function, but just the last four are the problem. They work only on Firefox and Chrome.
Do you have any idea why on Internet Explorer this does not work?
This is the part of the script that does not work:
[CODE=javascript]
function validate_fields ()
{
if (document.getEl ementById("comp ania").value.le ngth == "0")
{
document.getEle mentById("compa nia").style.bac kground = "#FD9B80";
submitOK="false ";
}
...............
var data = new String(document .getElementById ("data").value) ;
var month = data[3]+data[4];
var day = data[0]+data[1];
var year = data[6]+data[7]+data[8]+data[9];
var ready_h = document.getEle mentById("ready _h").value;
var ready_m = document.getEle mentById("ready _m").value;
var close_h = document.getEle mentById("close _h").value;
var close_m = document.getEle mentById("close _m").value;
var date_hour_ready = new Date(month + "/" + day + "/" + year + " " + ready_h + ":" + ready_m);
var date_hour_close = new Date(month + "/" + day + "/" + year + " " + close_h + ":" + close_m);
var last_booking_ho ur = new Date (month + "/" + day + "/" + year + " " + "19:00");
var first_booking_h our = new Date (month + "/" + day + "/" + year + " " + "09:00");
var current_date = new Date();
if (isNaN(ready_h) )
{
document.getEle mentById("ready _h").style.back ground = "#FD9B80";
submitOK="false ";
}
...............
if ((data_ora_clos e - data_ora_ready) < 2*60*60*1000)
{
document.getEle mentById("ready _h").style.back ground = "#FD9B80";
document.getEle mentById("ready _m").style.back ground = "#FD9B80";
document.getEle mentById("close _h").style.back ground = "#FD9B80";
document.getEle mentById("close _m").style.back ground = "#FD9B80";
alert("Pickup time should be at least 2 hours.");
submitOK="false ";
}
if (data_ora_ready <= current_date)
{
document.getEle mentById("ready _h").style.back ground = "#FD9B80";
document.getEle mentById("ready _m").style.back ground = "#FD9B80";
//alert("Ready by < closing time");
submitOK="false ";
}
if (data_ora_close > last_booking_ho ur)
{
document.getEle mentById("close _h").style.back ground = "#FD9B80";
document.getEle mentById("close _m").style.back ground = "#FD9B80";
alert("Last pickup time should be 19:00");
submitOK="false ";
}
if (data_ora_ready < first_booking_h our)
{
document.getEle mentById("ready _h").style.back ground = "#FD9B80";
document.getEle mentById("ready _m").style.back ground = "#FD9B80";
alert("You cannot register bookings earlier than 09:00");
submitOK="false ";
}
if (submitOK=="fal se")
{
return false;
}
}
[/CODE]
There are a lot of other ifs in that function, but just the last four are the problem. They work only on Firefox and Chrome.
Do you have any idea why on Internet Explorer this does not work?
Comment