Client Side Validation with JavaScript in ASP.NET
In jquery validate from date should not be greater than to date
<asp:TextBox ID="txtEffectiveFrom" runat="server"></asp:TextBox>
<AjaxControlToolkit:CalendarExtender ID="calEffectiveFrom" Format="dd/MM/yyyy" runat="server" TodaysDateFormat="dd, MM, yyyy" TargetControlID="txtEffectiveFrom" Enabled="True" >
</AjaxControlToolkit:CalendarExtender >
<asp:TextBox ID="txtJoiningDatemain" runat="server" "></asp:TextBox>
<AjaxControlToolkit:CalendarExtender ID="calJoiningDatemain" Format="dd/MM/yyyy"
runat="server" TodaysDateFormat="dd, MM, yyyy" TargetControlID="txtJoiningDatemain"
Enabled="True" OnClientDateSelectionChanged="checkDate">
</AjaxControlToolkit:CalendarExtender>
$('#txtEffectiveFrom').change(function () {
var txtjoiningDate = $("#txtJoiningDatemain").val();
if (txtjoiningDate == "") {
alert("Enter the Joining date !");
$('#txtEffectiveFrom').val('');
}
var txteffectivefrom = $('#txtEffectiveFrom').val();
spt_EventDateFrom = txtjoiningDate.split("/");
var changeformatfrom = spt_EventDateFrom[2] + spt_EventDateFrom[1] + spt_EventDateFrom[0];
spt_EventDateTo = txteffectivefrom.split("/"); // format change
var changeformatto = spt_EventDateTo[2] + spt_EventDateTo[1] + spt_EventDateTo[0];
if (changeformatfrom > changeformatto) {
alert("From joining Date should not be not greater than to Effective From date");
$('#txtEffectiveFrom').val('');
}
});
<asp:TextBox ID="txtEffectiveFrom" runat="server"></asp:TextBox>
<AjaxControlToolkit:CalendarExtender ID="calEffectiveFrom" Format="dd/MM/yyyy" runat="server" TodaysDateFormat="dd, MM, yyyy" TargetControlID="txtEffectiveFrom" Enabled="True" >
</AjaxControlToolkit:CalendarExtender >
<asp:TextBox ID="txtJoiningDatemain" runat="server" "></asp:TextBox>
<AjaxControlToolkit:CalendarExtender ID="calJoiningDatemain" Format="dd/MM/yyyy"
runat="server" TodaysDateFormat="dd, MM, yyyy" TargetControlID="txtJoiningDatemain"
Enabled="True" OnClientDateSelectionChanged="checkDate">
</AjaxControlToolkit:CalendarExtender>
$('#txtEffectiveFrom').change(function () {
var txtjoiningDate = $("#txtJoiningDatemain").val();
if (txtjoiningDate == "") {
alert("Enter the Joining date !");
$('#txtEffectiveFrom').val('');
}
var txteffectivefrom = $('#txtEffectiveFrom').val();
spt_EventDateFrom = txtjoiningDate.split("/");
var changeformatfrom = spt_EventDateFrom[2] + spt_EventDateFrom[1] + spt_EventDateFrom[0];
spt_EventDateTo = txteffectivefrom.split("/"); // format change
var changeformatto = spt_EventDateTo[2] + spt_EventDateTo[1] + spt_EventDateTo[0];
if (changeformatfrom > changeformatto) {
alert("From joining Date should not be not greater than to Effective From date");
$('#txtEffectiveFrom').val('');
}
});
Comments
Post a Comment