[RESOLVED]Issue with summary in the function

Hi,

    I am trying to validate dates..from frontend.

If i enter from date and if left todate — it has to show alert as todate is required but not sure in the sumamry already From-date should be ‘less’ than to-date & to-date should be ‘greater’ than from-date is available then its combining with todate alert.

if i enter todate and left from date that is showing fine i am able to see single alert like from date is required..

<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="return validate();" />

function validate() {
var summary = "";
summary += isvaliddate();
summary += isvalidDatefrom();
summary += isvalidDateto();
if (summary != "") {
alert(summary);
return false;
}
else {
return true;
}
}



function isvaliddate() {
var RadTimePicker1 = $find("<%= rdtpDateFrom.ClientID %>");
//Get the Datepickeer2
var RadTimePicker2 = $find("<%= rdtpDateTo.ClientID %>");
//Get the selected values
var Date1 = new Date(RadTimePicker1.get_selectedDate());
var Date2 = new Date(RadTimePicker2.get_selectedDate());
//Check if Datel is less than Date2
if ((Date2 - Date1) < 0) {
//if so then show the message
return("From-date should be 'less' than to-date & to-date should be 'greater' than from-date");
}
else {
return "";
}
}

function isvalidDatefrom() {
var uid;
var temp = document.getElementById("<%=rdtpDateFrom.ClientID %>");
uid = temp.value;
if (uid == "") {
return ("Please enter Appeal Date-From" + "n");
}
else {
return "";
}
}

function isvalidDateto() {
var uid;
var temp = document.getElementById("<%=rdtpDateTo.ClientID %>");
uid = temp.value;
if (uid == "") {
return ("Please enter Appeal Date-To" + "n");
}
else {
return "";
}
}

Any help plz…

The reason behind this issue was Telerik RadDatePicker will have the Minimum value assigned to it by default. so if you dont select any date, at run time, the control will have the minimum date value when you use the below code

var Date1 = new Date(RadTimePicker1.get_selectedDate());

and this causes the code to execute in isValidate() along with the isvalidDatefrom() function and thats why you have two messages at a time.

As solution you can try this approach check if the FromDate is lessthan ToDate only if user enter values in both the textboxes.

Please use the sample code

Complete Code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">

            function validate() {
                var summary = "";
                summary += isvalidDatefrom();
                summary += isvalidDateto();
                //Validate only if you have entered values in both textboxes
                if (summary == "") {
                    summary += isvaliddate();
                }
                if (summary != "") {
                    alert(summary);
                    return false;
                }
                else {
                    return true;
                }
            }

            function isvaliddate() {
                var RadTimePicker1 = $find("<%= rdtpDateFrom.ClientID %>");
                //Get the Datepickeer2
                var RadTimePicker2 = $find("<%= rdtpDateTo.ClientID %>");
                //Get the selected values
                var Date1 = new Date(RadTimePicker1.get_selectedDate());
                var Date2 = new Date(RadTimePicker2.get_selectedDate());
                //Check if Datel is less than Date2
                if ((Date2 - Date1) < 0) {
                    //if so then show the message
                    return ("From-date should be 'less' than to-date & to-date should be 'greater' than from-date");
                }
                else {
                    return "";
                }
            }

            function isvalidDatefrom() {
                var uid;
                var temp = document.getElementById("<%=rdtpDateFrom.ClientID %>");
                uid = temp.value;
                if (uid == "") {
                    return ("Please enter Appeal Date-From" + "n");
                }
                else {
                    return "";
                }
            }

            function isvalidDateto() {
                var uid;
                var temp = document.getElementById("<%=rdtpDateTo.ClientID %>");
                uid = temp.value;
                if (uid == "") {
                    return ("Please enter Appeal Date-To" + "n");
                }
                else {
                    return "";
                }
            }
        </script>
    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:Label runat="server" ID="Label1" Text="FromDate"></asp:Label>
    <telerik:RadDatePicker ID="rdtpDateFrom" runat="server" DateInput-DisplayDateFormat="MM/dd/yyyy">
    </telerik:RadDatePicker>
    <asp:Label runat="server" ID="Label2" Text="ToDate"></asp:Label>
    <telerik:RadDatePicker ID="rdtpDateTo" runat="server" DateInput-DisplayDateFormat="MM/dd/yyyy">
    </telerik:RadDatePicker>
    <asp:Button ID="Button2" runat="server" Text="Button" OnClientClick="return validate();" />
    </form>
</body>
</html>

Leave a Reply