Unknown error when calling Array.length

First of all I need to say that I don't have much experience with JS. I am currently trying to implement a web application with an MVC map. I am working on developing an application that is also compatible with Internet Explorer. in this case I am using the following JS method to populate the table, which works fine with all browsers ....

function populateTable(array) {
document.getElementById("instalationTable").style.display = "block";
var table = document.getElementById("ActivityDescription_installationID");
table.innerHTML = "";
elementsInTable = array;
var x = 0;
for (i = 0; i < (array.length * 2) ; i++) {
    //alert(i);
    if ((i % 2) == 0) {
        //ID Row

        var row = table.insertRow(i);

        var cell_1 = row.insertCell(0);
        cell_1.innerHTML = "<input type='text' disable='' class='form-control' value=" + array[x]     + ">";
        x = x + 1;

        var cell_2 = row.insertCell(1);
        cell_2.innerHTML = "<span class='btn btn-default' onclick='showEditRow(this)'><img src='../../Content/images/1414409386_48-24.png' /></span>";

        var cell_3 = row.insertCell(2);
        cell_3.innerHTML = "<span class='btn btn-default' onclick='removeRow(this)'>X</apan>";
    }
    else {
        //Detail Row
        var rowDetails = table.insertRow(i);
        var cell = rowDetails.insertCell(0);
        //cell.colspan = "3";
        cell.innerHTML = "<table style='background-color:rgb(98, 98, 98);color:black;border- radius: 5px;' margin:2%; >" +
            "<tr>" +
                "<td><input type='checkbox' id='"+x+"_appServer'/> Application Server</span></td>" +
                "<td>" +
                    "<select id='" + x + "_appServerVersion'>" +
                        "<option>Application version</option>" +
                    "</select>" +
                "</td>" +
            "</tr>" +
            "<tr>" +
                "<td colspan='2'><input type='radio' name='database' id='"+x+"_emptyDb' onChange='enableOptions(1)'/>" +
                " Empty Database</br><input type='radio' name='database' id='" + x + "_instalationSlt' onChange='enableOptions(2)'/> Something Databse</td>" +
            "</tr>" +

            "<tr id='emptyDB'>" +
                "<td>" +
                    "Oracle Version"+
                    "<select id='JS_OraVersion' name='" + x + "_oraVersion' style='width:100%'>" +
                        "<option>Ora version</option>" +
                    "</select>" +
                "</td>" +
                "<td>" +
                    "Character Set" +
                    "<select id='JS_ChaSet' name='" + x + "_ChaSet' style='width:100%'>" +
                        "<option>Cha Set</option>" +
                    "</select>" +
                "</td>" +
            "</tr>" +
            "<tr id='dbImport'>" +
                "<td>" +
                    "Something version" +
                    "<select id='JS_ImportVersion' name='" + x + "_ImportVersion' style='width:100%'>" +
                        "<option>Something version</option>" +
                    "</select>" +
                "</td>" +
                "<td>" +
                    "Something Charachter" +
                    "<select id='JS_ImportChaSet' name='" + x + "_ImportChaSet' style='width:100%'>" +
                        "<option>Something Cha</option>" +
                    "</select>" +
                "</td>" +
            "</tr>" +
            "<tr>" +
                "<td colspan='2'>" +
                    "Additional Requests </br>" +
                    "<textarea rows='4' id='" + x + "_specialReq' cols='37'> </textarea>" +
                "<td/>"+
            "</tr>"+
            "</table>";
        rowDetails.style.display = 'none';
        Lock();
    }
}
document.getElementById("instalationTable").style.display = "block";

      

}

I am filling out a form in the above row of the spreadsheet that collects some data to proceed. to collect data I am using the following function which works fine with Google Chrome but not Internet Explorer.

function getAllData() {
var StringtoSent = "";
for (i = 0; i < (elementsInTable.length) ; i++) {
    var InsId = elementsInTable[i];
    var _appServer = document.getElementById((i + 1) + "_appServer").checked;
    var _appServerVersionDropDown = document.getElementById((i + 1) + "_appServerVersion");
    var _appServerVersion = _appServerVersionDropDown.options[_appServerVersionDropDown.selectedIndex].value;
    var _emptyDb = document.getElementById((i + 1) + "_emptyDb").checked;
    var _instalationSlt = document.getElementById((i + 1) + "_instalationSlt").checked;
    var _oraVersionDropDown = document.getElementsByName((i + 1) + "_oraVersion")[0];
    var _oraVersion = _oraVersionDropDown.options[_oraVersionDropDown.selectedIndex].value;
    var _ChaSetDropDown = document.getElementsByName((i + 1) + "_ChaSet")[0];
    var _ChaSet = _ChaSetDropDown.options[_ChaSetDropDown.selectedIndex].value;
    var _ImportVersionDropDown = document.getElementsByName((i + 1) + "_ImportVersion")[0];
    var _ImportVersion = _ImportVersionDropDown.options[_ImportVersionDropDown.selectedIndex].value;
    var _ImportChaSetDropDown = document.getElementsByName((i + 1) + "_ImportChaSet")[0];
    var _ImportChaSet = _ImportChaSetDropDown.options[_ImportChaSetDropDown.selectedIndex].value;
    var _specialReq = document.getElementById((i + 1) + "_specialReq").value;

    StringtoSent = StringtoSent + "," + InsId + "," + _appServer + "," + _appServerVersion + "," + _emptyDb + "," + _instalationSlt + "," + _oraVersion + "," + _ChaSet + "," + _ImportVersion + "," + _ImportChaSet + "," + _specialReq + "|";
    //return StringtoSent;
    document.getElementById("ActivityDescription_instalationDetails").value = StringtoSent;

}

      

}

the following image shows the error im getting when it crashes on VS 2012s IIS Express.    enter image description here

for (i = 0; i < (elementsInTable.length) ; i++) {

      

is the location that indicates the location of the error. it always highlights the "elementsInTable.length" code segment.

In fact, this error message does not produce anything. I found several articles about the same error, but came up when trying to change the inner HTML of an element. but these solutions are not compatible for this situation. Please help me with the problem.

early

+3


source to share


1 answer


Finally I encountered the error

        cell.innerHTML = "<table style='background-color:rgb(98, 98, 98);color:black;border- radius: 5px;' margin:2%; >" +

      

in the above line, I mistakenly added the "margin: 2%;" CSS attribute in the wrong place. Google Chrome is smart enough to manage the situation and keep going, but Internet Explorer isn't. as I found it is the fact that suggests the same error in different situations.

EG:

http://www.webdeveloper.com/forum/showthread.php?22946-innerHTML-amp-IE-Unknown-Runtime-Error http://www.webdeveloper.com/forum/showthread.php?22946-innerHTML-amp -IE-Unknown-Runtime-Error



So, if you have any unknown error in your Java Script that uses "element.InnerHTML" or "document.Write", it's best to check if your tags are properly closed.

and I found several other situations that generate the same error

in most cases, you can avoid this error by following the W3C tagging guidelines ( http://www.w3.org/TR/html401/struct/global.html ).

+2


source







All Articles