Hi everyone, I am developing with a Visual Studio 2015 an Asp.Net core MVC project and in one of the razor pages there is the following javascript code:
<script> document.addEventListener("DOMContentLoaded", init, false); var filterDiv = ""; var filterArea = ""; var filterDividerUp = ""; var filters_string = ""; var filter_number = 0; var fields_list = []; var selectArray = []; var import_id = @lastImportId; var managementTable = ""; managementTable = "@managementTableName"; //fields_list = new Array(); fields_list = @Html.Raw(Json.Serialize(fieldsList)); filters_string = @Html.Raw(Json.Serialize(filters)); function init() { filterDiv = document.getElementById("filterDiv"); filterArea = document.getElementById("filterArea"); filterDividerUp = document.getElementById("filterDividerUp"); initFilter(); } function initFilter() { var filters = []; var filter_parts = []; var filter_values = []; var html = "<div class=\"row\">"; html += "<div class=\"col-md-3\"></div>"; html += "<div class=\"col-md-2\">"; html += "<p>Field</p>"; html += "</div>"; html += "<div class=\"col-md-1\">"; html += "<p style=\"text-align:center\"> </p>"; html += "</div>"; html += "<div class=\"col-md-4\">"; html += "<p>Value</p>"; html += "</div>"; html += "<div class=\"col-md-2\"></div>"; html += "</div>"; if(filters_string == ""){ filters.length = 0; } else{ filters = filters_string.split("|"); } for (f = 0; f < filters.length; f++) { filter_number++; html += "<div class=\"row\">"; filter_parts = filters[f].split("§"); html += "<div class=\"col-md-3\"></div>"; html += "<div class=\"col-md-2\">"; html += "<select id=\"fieldsSelector" + filter_number + "\" name=\"fieldsSelector" + filter_number + "\" class=\"form-control\" data-width=\"auto\" onchange=\"getValuesList('fieldsSelector" + filter_number + "', 'valuesSelector" + filter_number + "', '')\">"; for (fd = 0; fd < fields_list.length; fd++) { html += "<option id=\"option" + fd + "fieldsSelector" + filter_number + "\" value=\"" + fields_list[fd] + "\"" + (filter_parts[0] == fields_list[fd] ? " selected" : "") + ">" + fields_list[fd] + "</option>"; } html += "</select>"; html += "</div>"; html += "<div class=\"col-md-1\">"; html += "<p style=\"text-align:center\">=</p>"; html += "</div>"; //filter_values = filter_parts[1].split("::"); //for(v = 0; v < filter_values.length; v++){ // html += filter_values[v] + (v == filter_values.length - 1 ? "" : "-"); //} html += "<div class=\"col-md-4\">"; html += "<select id=\"valuesSelector" + filter_number + "\" name=\"valuesSelector" + filter_number + "\" class=\"form-control\" data-width=\"auto\" onchange=\"setFilters('fieldsSelector" + filter_number + "', 'valuesSelector" + filter_number + "')\">"; html += "<option id=\"option0valuesSelector" + filter_number + "\" value=\"" + filter_parts[1] + "\" selected>Please Select</option>"; html += "</select>"; html += "</div>"; selectArray[f] = "fieldsSelector" + filter_number + "-" + "valuesSelector" + filter_number + "-" + filter_parts[1]; html += "<div class=\"col-md-2\"></div>"; html += "</div>"; } filterArea.innerHTML = html; if(filter_number > 0){ for(var s = 0; s < selectArray.length; s++){ var splitSelect = selectArray[s].split("-"); getValuesList(splitSelect[0], splitSelect[1], splitSelect[2]); } } } function getValuesList(changingSelectorId, loadingSelectorId, selectedItem) { var selectedField = ""; selectedField = $("#" + changingSelectorId).val();$.ajax({ type: 'GET', dataType: 'json', contentType: 'application/json', url: '@Url.Action("GetData", "AjaxDatabaseManager")', data: { lookupTable : JSON.stringify(managementTable), lookupField : JSON.stringify(selectedField), importid : import_id}, success: function (result) { var optionNumber = 1; var resultObj = result; //JSON.parse(result); $("#" + loadingSelectorId).empty(); // remove old options$("#" + loadingSelectorId).append("<option id=\"pleaseselect" + loadingSelectorId + "\" value=\"pleaseSelect\" " + (selectedItem == ""? "selected": "") + ">Please Select</option>");$.each(resultObj, function(key, val){$("#" + loadingSelectorId).append("<option id=\"option" + optionNumber + loadingSelectorId + "\" value=\"" + val + "\" " + (selectedItem != "" && val == selectedItem? "selected": "") + ">" + val + "</option>"); optionNumber++; }); } }); }</script>
Occasionally, after following the same steps in previous navigation if open the same page, the following errors occur:
Errore pagina web ----------------- Errore: Errore non specificato. Errore pagina web ----------------- Errore: Impossibile recuperare la proprietà 'addEventListener' di un riferimento nullo o non definito Errore pagina web ----------------- Errore: Impossibile recuperare la proprietà 'createElement' di un riferimento nullo o non definito Errore pagina web ----------------- Errore: Bootstrap's JavaScript requires jQuery Errore pagina web ----------------- Errore: Impossibile recuperare la proprietà 'valHooks' di un riferimento nullo o non definito Errore pagina web ----------------- Errore: Impossibile recuperare la proprietà 'createElement' di un riferimento nullo o non definito Errore pagina web ----------------- Errore: Impossibile recuperare la proprietà 'createElement' di un riferimento nullo o non definito
Would you like to point to the javascript code what is wrong? I'm going crazy!
Thank you
Paolo