locked
Not getting the 'innerHTML' value on postback.Undefined error RRS feed

  • Question

  • User411771660 posted

    This is still working on firefox,internet explorer.I have an aspx page for reports.On page load it calls for the page title from base-master-page.js as.

    debugger;
    var title = document.getElementsByTagName("title")[0].innerHTML;
    var baseURL = function () {
        if (!location.origin) {
            location.origin = location.protocol + "//" + location.host;
        }
        return location.origin;
    };

    Since this calls for page title.It gets from masterpage.

    protected void Page_Load(object sender, EventArgs e)
        {
            PageTitlePlaceHolder.Text = PageTitle + " - Planet CBS | Powered By PES";
            {
                int userId = UserId;
                string menuUlLi = Menu.GetMenu(UserId, OfficeId);
                MenuUl.InnerHtml = menuUlLi;
    
                AppTitle.Text = "Everest ";
                AppVersion.Text = "CBS";
    
                if (Session["UserName"] != null)
                {
                    UserLiteral.Text = Session["UserName"].ToString();
                    UserNameLiteral.Text = Session["UserName"].ToString();
                }
    
                if (Session["OfficeName"] != null)
                {
                    RoleLiteral.Text = Session["OfficeName"].ToString();
                }
    
                if (Session["Phone"] != null)
                {
                    PhoneNumberLiteral.Text = Session["Phone"].ToString();
                }
            }
        }

    Works well with other pages.But with one page TrialBalance.aspx.This page calls for trialbalance.js

    $(document).on('TrialBalancePrepareSuccess', function () {
        try {
            var url = '/WebMethods/Vouchers.asmx/GetCumulativeTrialBalance';
            //var d = { date: $('#ValueDateTextBox').val(), level: 0 };
            var jqXhr = ajaxPost(url, null);
            jqXhr.done(function (data) {
                var ret = data.d;
                if (ret) {
                    var div = $('#ReportTable').empty();
                    var drTotal = 0;
                    var crTotal = 0;
                    div.append(
                        $("<tr><th>Title</th><th>Debit</th><th>Credit</th><th>Balance</th></tr>"));
    
                    $(data.d).each(function (index, item) {
                        if (parseFloat(item.Debit) !== 0 || parseFloat(item.Credit) !== 0) {
                            drTotal += parseFloat(item.Debit);
                            crTotal += parseFloat(item.Credit);
    
                            var balance = parseFloat(item.Debit) - parseFloat(item.Credit);
                            if (parseFloat(balance) < 0) {
                                balance = parseFloat(balance) * (-1);
                            }
                            if (item.Debit === 0) {
                                item.Debit = "-";
                            }
                            if (item.Credit === 0) {
                                item.Credit = "-";
                            }
    
                            if (item.IsGroup) {
                                div.append(
                                    $("<tr class='GroupTr cursor-pointer'>")
                                    .append($("<td>").html("<input type='hidden' class='GlAccountId' value = '" + item.GlAccountId + "'/>" +
                                        "<input type='hidden' class='ParentId' value = '" + item.ParentId + "'/>" + "<input type='hidden' class='AcLevel' value = '" + item.AcLevel + "'/>" + item.Title))
                                    .append($("<td class='text-center'>").html(item.Debit))
                                    .append($("<td class='text-center'>").html(item.Credit))
                                    .append($("<td class='text-center'>").html("<input type='hidden' class='IsGroup' value = '" + item.IsGroup + "'/><input type='hidden' class='IsExpanded' value = 'false'/>" + balance)));
                            } else {
                                div.append(
                                    $("<tr class='LedgerTr'>")
                                    .append($("<td>").html("<input type='hidden' class='GlAccountId' value = '" + item.GlAccountId + "'/>" +
                                        "<input type='hidden' class='ParentId' value = '" + item.ParentId + "'/>" + "<input type='hidden' class='AcLevel' value = '" + item.AcLevel + "'/>" + item.Title))
                                    .append($("<td class='text-center'>").html(item.Debit))
                                    .append($("<td class='text-center'>").html(item.Credit))
                                    .append($("<td class='text-center'>").html("<input type='hidden' class='IsGroup' value = '" + item.IsGroup + "'/><input type='hidden' class='IsExpanded' value = 'false'/>" + balance)));
                            }
                        }
                    });
                    div.append($("<tr><th>Total</th><th>" + drTotal.toFixed(2) + "</th><th>" + crTotal.toFixed(2) + "</th><th></th></tr>"));
    
                    $('#ReportTable tr').each(function () {
                        var row = $(this).closest('tr');
    
                        var isExpanded = row.find('.IsExpanded').val();
                        if (isExpanded === "false") {
                            CumulativeDetails(row);
                        }
                    });
                }
            });
        } catch (e) {
    
        }
    });

    And the .js code in the Trialbalance.aspx page.

    asp:Content ID="Content4" ContentPlaceHolderID="BottomScriptContentPlaceholder" runat="server">
        <script src="../../Scripts/trial-balance.js"></script>
        <script type="text/javascript">
            $('#ShowButton').on('click', function () {
                var isAllBranch = $('#IsCumulativeCheckBox').is(':checked');
                var officeId = 0;
                var officeName = "";
                if (!isAllBranch) {
                    officeId = $('#OfficeDropDownList').val();
                    officeName = $('#OfficeDropDownList option:selected').text();
                }
                var rptType = $('#TypeRadio input[type=radio]:checked').val();
                $("#DDLOfficeID").val(officeId);
                $("#officeName").val(officeName);
                $("#rptType").val(rptType);
                $("#FromDateTextBox").val($('#FromDateDiv').find('#ValueDateTextBox').val());
                $("#ToDateTextBox").val($('#ToDateDiv').find('#ValueDateTextBox').val());
            });
            $('#TypeRadio').on('click', function () {
                var selected = $('#TypeRadio input[type=radio]:checked').val();
                if (selected === "cum") {
                    $('#FromDateDiv').fadeOut(500);
                } else {
                    $('#FromDateDiv').fadeIn(500);
                }
            });
        </script>
    </asp:Content>

    On debugging error throws at the base-master-page.js with

    Cannot read property 'innerHTML' of undefined..This works well with other pages.It was indeed working a few weeks back.Bad param for the question.I apologize if this question was too naive or anything.downvote too shall follow.Thank You.Help please

    Sunday, June 24, 2018 5:26 PM

All replies

  • User-1171043462 posted

    Which line error is coming?

    Sunday, June 24, 2018 7:51 PM
  • User411771660 posted

    Getting error here sir

    var title = document.getElementsByTagName("title")[0].innerHTML;
    Monday, June 25, 2018 8:29 AM
  • User-1171043462 posted

    Try using

    var title = document.title;

    Demo here

    Get Title of HTML Page using JavaScript

    Monday, June 25, 2018 5:45 PM
  • User411771660 posted

    Not working sir.

    Tuesday, June 26, 2018 9:17 AM
  • User-1171043462 posted

    I have given you demo too.

    If it is not working then either your Title tag is missing on page or nor properly formed.

    Tuesday, June 26, 2018 2:10 PM