I need to perform validation in JavaScript by comparing DATES
and TIME
.
I need to have the date in dd/MM/yyyy format, but I am unsure of the format it is currently taking. After debugging the JavaScript code, I discovered the format. The screenshot below shows a different date than the one I am inserting as TODAYS
date.
https://i.sstatic.net/OMlw0.png
Below is the code snippet:-
function ValidateRecord() {
var StrPriError = "";
if (document.getElementById('TextBox1').value == "" || document.getElementById('TextBox2').value == "" || document.getElementById('TextBox3').value == "" || document.getElementById('TextBox4').value == "") {
StrPriError += "Dates cannot be blank \n";
}
else {
var dt1 = new Date(document.getElementById('TextBox1').value + " " + document.getElementById('DrpTime').value);
var dt2 = new Date(document.getElementById('TextBox2').value + " " + document.getElementById('DrpTime3').value);
var dt3 = new Date(document.getElementById('TextBox3').value + " " + document.getElementById('DrpTime4').value);
var dt4 = new Date(document.getElementById('TextBox4').value + " " + document.getElementById('DrpTime5').value);
if (dt1.getTime() == dt2.getTime() || dt1.getTime() == dt3.getTime() || dt1.getTime() == dt4.getTime() || dt2.getTime() == dt3.getTime() || dt2.getTime() == dt4.getTime() || dt3.getTime() == dt4.getTime()) {
StrPriError += "Dates and Times cannot be the same \n";
}
else {
// StrPriError += "Good to go \n";
}
if (dt2.getTime() < dt1.getTime()) {
StrPriError += "Reminder 2 cannot be less than reminder 1 \n";
}
if (dt3.getTime() < dt1.getTime()) {
StrPriError += "Reminder 3 cannot be less than reminder 1 \n";
}
if (dt4.getTime() < dt1.getTime()) {
StrPriError += "Reminder 4 cannot be less than reminder 1 \n";
}
if (dt3.getTime() < dt2.getTime()) {
StrPriError += "Reminder 3 cannot be less than reminder 2 \n";
}
if(dt4.getTime() < dt2.getTime()) {
StrPriError += "Reminder 4 cannot be less than reminder 2 \n";
}
if (dt4.getTime() < dt3.getTime()) {
StrPriError += "Reminder 4 cannot be less than reminder 3 \n";
}
}
if (StrPriError != "") {
alert(StrPriError);
return false;
}
else {
return true;
}
}
Additionally, here is the associated HTML:-
<td colspan="1px" style="width: 13%" class="field">
<asp:TextBox ID="TextBox1" runat="server" Width="80" Enabled="false"></asp:TextBox>
<cc3:Calendar ID="Calendar1" runat="server" DatePickerMode="true" TextBoxId="TextBox1"
DatePickerImagePath="../../Images/icon2.gif" CultureName="en-GB">
</cc3:Calendar>
<asp:DropDownList ID="DrpTime" runat="server" Width="65px">
<asp:ListItem Value="09:00">09:00</asp:ListItem>
<asp:ListItem Value="13:00">13:00</asp:ListItem>
<asp:ListItem Value="17:00">17:00</asp:ListItem>
<asp:ListItem Value="21:00">21:00</asp:ListItem>
</asp:DropDownList>
</td>
<td colspan="1px" style="width: 13%" class="field">
<asp:TextBox ID="TextBox2" runat="server" Width="80" Enabled="false"></asp:TextBox>
<cc3:Calendar ID="Calendar2" runat="server" DatePickerMode="true" TextBoxId="TextBox2"
DatePickerImagePath="../../Images/icon2.gif" CultureName="en-GB">
</cc3:Calendar>
<asp:DropDownList ID="DrpTime3" runat="server" Width="65px">
<asp:ListItem Value="09:00">09:00</asp:ListItem>
<asp:ListItem Value="13:00">13:00</asp:ListItem>
<asp:ListItem Value="17:00">17:00</asp:ListItem>
<asp:ListItem Value="21:00">21:00</asp:ListItem>
</asp:DropDownList>
</td>
This issue is preventing me from properly validating. Any suggestions on how to resolve this?