locked
Javascript function not working in IE 8 RRS feed

  • Question

  • User-1506965535 posted

    I have written a javascript function for start date and end date, its working fine in chrome but it is not working in IE. Any alternate solution ??

    Here is my code

    function DateValidation(startDate, EndDate) {
                if (startDate != '' && EndDate != '') {
                    var stdate = Date.parse(GrdPreEmp_Det_TempPrevStartDate_ctl00_txtPrevStartdate.value);
                    var enddate = Date.parse(GrdPreEmp_Det_TempEndDate_ctl00_txtPrevEndDate.value);
                    if (stdate > enddate) {
                        alert('Start date cannot be greater than end date');
                        return false;
                    }
                    else {
                        return true;
                    }
                } 
            }
    
    
    
    <cc1:Grid ID="GrdPreEmp_Det" EnableTypeValidation="true" runat="server" Width="99%"
                AllowAddingRecords="true" AllowSorting="false" AutoGenerateColumns="false" FolderStyle="../../Styles/Grid/style_13"
                OnInsertCommand="GrdPreEmp_Det_InsertCommand" OnDeleteCommand="GrdPreEmp_Det_DeleteCommand"
                OnRebind="GrdPreEmp_Det_OnRebind" OnRowDataBound="GrdPreEmp_Det_RowDataBound">
                <ClientSideEvents OnBeforeClientAdd="GrdPreEmp_Det_OnBeforeClientAdd" OnBeforeClientDelete="GrdPreEmp_Det_OnClientDelete"
                    OnBeforeClientInsert="GrdPreEmp_Det_nBeforeClientInsert" OnClientInsert="GrdPreEmp_Det_OnClientInsert" />
                <Columns>
                    <cc1:Column AllowDelete="true" HeaderText="Delete" Width="8%">
                    </cc1:Column>
                    <cc1:Column ID="Column1" DataField="MKEY" HeaderText="Mkey" Visible="false" Width="0%"
                        ReadOnly="true">
                    </cc1:Column>
                    <cc1:Column ID="Column2" DataField="SR_NO" HeaderText="Sr No" Visible="true" Width="6%"
                        ReadOnly="true">
                        <TemplateSettings TemplateId="GridTemplate1" />
                    </cc1:Column>
                    <cc1:Column ID="CompanyName" DataField="CompanyName" HeaderText="Company Name" Visible="true"
                        Width="15%">
                    </cc1:Column>
                    <cc1:Column ID="Location" DataField="Location" HeaderText="Location" Visible="true"
                        Width="12%">
                    </cc1:Column>
                    <cc1:Column ID="StartDate" DataField="StartDate" HeaderText="Start Date" Visible="true"
                        Width="12%">
                        <TemplateSettings EditTemplateId="TempPrevStartDate" />
                    </cc1:Column>
                    <cc1:Column ID="EndDate" DataField="EndDate" HeaderText="End Date" Visible="true"
                        Width="12%">
                        <TemplateSettings EditTemplateId="TempEndDate" />
                    </cc1:Column>
                    <cc1:Column ID="LastHeld" DataField="LastHeld" HeaderText="Last Held Designation"
                        Visible="true" Width="15%">
                    </cc1:Column>
                    <cc1:Column ID="Reason" DataField="Reason" HeaderText="Reason Of Leaving" Visible="true"
                        Width="15%">
                    </cc1:Column>
                    <cc1:Column ID="Column33" DataField="Attachment" HeaderText="Attachments" Visible="true"
                        Width="110px">
                        <TemplateSettings EditTemplateId="GridPrevAttach" />
                    </cc1:Column>
                    <cc1:Column ID="Column34" DataField="xyz123" HeaderText="" AllowEdit="false" Visible="true"
                        Width="10px">
                    </cc1:Column>
                    <cc1:Column ID="Column38" DataField="TextName" HeaderText="" Visible="false" Width="0px">
                        <TemplateSettings TemplateId="GridPrevAttaBtn" />
                    </cc1:Column>
                </Columns>
                <Templates>
                    <cc1:GridTemplate runat="server" ID="GridPrevAttaBtn" ControlID="btnPrevEmpText">
                        <Template>
                            <asp:ImageButton ID="btnPrevEmpText" runat="server" OnClientClick="funAttachment_grid('PEC')"
                                ImageUrl="~/Images/AttachIcon.png" />
                        </Template>
                    </cc1:GridTemplate>
                    <cc1:GridTemplate runat="server" ID="GridTemplate1">
                        <Template>
                            <b>
                                <%# (Container.RecordIndex + 1) %></b>
                        </Template>
                    </cc1:GridTemplate>
                    <cc1:GridTemplate runat="server" ID="GridTemplate2" ControlID="txtDate" ControlPropertyName="value">
                        <Template>
                            <table cellspacing="0" cellpadding="0" style="border-collapse: collapse;">
                                <tr>
                                    <td valign="top">
                                        <input type="text" id="txtDate1" class="ob_gEC" style="width: 85px;" />
                                    </td>
                                    <td valign="top">
                                        <cc3:Calendar ID="caltxtDate1" runat="server" DatePickerMode="true" DateFormat="dd-MM-yyyy"
                                            TextBoxId="txtDate1" DatePickerImagePath="Images/icon2.gif" />
                                    </td>
                                </tr>
                            </table>
                        </Template>
                    </cc1:GridTemplate>
                    <cc1:GridTemplate runat="server" ControlID="txtPrevStartdate" ID="TempPrevStartDate">
                        <Template>
                            <asp:TextBox ID="txtPrevStartdate" onblur="DateValidation(this)" runat="server" ToolTip="Enter date in DD/MM/YYYY format"></asp:TextBox>
                        </Template>
                    </cc1:GridTemplate>
                    <cc1:GridTemplate runat="server" ControlID="txtPrevEndDate" ID="TempEndDate">
                        <Template>
                            <asp:TextBox ID="txtPrevEndDate" runat="server" onblur="DateValidation(this)" ToolTip="Enter date in DD/MM/YYYY format"></asp:TextBox>
                        </Template>
                    </cc1:GridTemplate>
                    <cc1:GridTemplate runat="server" ID="GridPrevAttach" ControlID="btnAttachPrev">
                        <Template>
                            <asp:Image ID="btnAttachPrev" ImageUrl="~/Images/Attachment.png" runat="server" onclick="funAttachment_grid('PEC')" />
                        </Template>
                    </cc1:GridTemplate>
                </Templates>
                <AddEditDeleteSettings AddLinksPosition="Bottom" NewRecordPosition="Dynamic" />
            </cc1:Grid>

    Wednesday, September 2, 2015 3:06 AM

Answers

  • User-1506965535 posted

    There was issue with the ID, Though I got it resolved like below:-

    function DateValidation_Prev(startDate, EndDate) {
                if (startDate != '' && EndDate != '') {
                    var stdate = Date.parse(document.getElementById('GrdPreEmp_Det_TempPrevStartDate_ctl00_txtPrevStartdate').value);
                    var enddate = Date.parse(document.getElementById('GrdPreEmp_Det_TempEndDate_ctl00_txtPrevEndDate').value);
                    if (stdate > enddate) {
                        alert('Start date cannot be greater than end date');
                        document.getElementById('GrdPreEmp_Det_TempEndDate_ctl00_txtPrevEndDate').focus();
                        return false;
                    }
                    else {
                        return true;
                    }
                }
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 3, 2015 8:36 AM

All replies

  • User-271186128 posted

    Hi Nadeem,

    its working fine in chrome but it is not working in IE.

    As for this issue, I suggest you could set a break point in the DateValidation function and make sure it can be called in IE. Then, you could use F12 developer tools to debug your code to see whether it contains some JavaScript error.

    From my point of view, I suggest you could try to use the JQuery DatePicker to select a date range.

    For details about DatePicker, please see: https://jqueryui.com/datepicker/

    Best Regards,
    Dillion

    Thursday, September 3, 2015 5:43 AM
  • User-1506965535 posted

    There was issue with the ID, Though I got it resolved like below:-

    function DateValidation_Prev(startDate, EndDate) {
                if (startDate != '' && EndDate != '') {
                    var stdate = Date.parse(document.getElementById('GrdPreEmp_Det_TempPrevStartDate_ctl00_txtPrevStartdate').value);
                    var enddate = Date.parse(document.getElementById('GrdPreEmp_Det_TempEndDate_ctl00_txtPrevEndDate').value);
                    if (stdate > enddate) {
                        alert('Start date cannot be greater than end date');
                        document.getElementById('GrdPreEmp_Det_TempEndDate_ctl00_txtPrevEndDate').focus();
                        return false;
                    }
                    else {
                        return true;
                    }
                }
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 3, 2015 8:36 AM
  • User475983607 posted

    You still have an issue with the function arguments. StartDate and EndDate are validated against an empty string but only one argument is ever passed to the this function.  That argument happens to be an object (this).  Since startDate equals an object and not empty string and endDate is undefined which is also not equal to an empty string the condition always evaluates to true.

    if (startDate != '' && EndDate != '') {

    Please take a few minutes to review your code.

    Thursday, September 3, 2015 11:11 AM