Only on Firefox do I get this error:
Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.
if (c.checked == 1)
GFPart...vitate= (line 17)
TypeError: c is null
if (c.checked == 1)
My Javascript look like this:
<script type="text/javascript">
function SavePartners() {
var poz = '@ViewBag.Activity';
var rowCount = dataTable.rows.length;
var ala0 = "";
for (var i = 1; i < rowCount; i++) {
var c = document.getElementById("chkpart" + i);
if (c.checked == 1)
ala0 += dataTable.rows[i].cells[1].innerText + "^";
var ala = ala0.substring(0, ala0.length - 1);
}
$.ajax({
url: '@Url.Action("TPartners")',
data: { pozActivitate: poz, listapart: ala },
dataType: "Json",
type: "POST",
error: function () {
alert("Error");
},
success: function (data) {
window.close();
}
});
}
My HTML look like this (its a table with 2 columns, 1 with Checkbox and 2 with the Name of the partner)
<tr>
<td style="border-left: none;">
@if (listaDeTest.Activity!= 0)
{
string x = (from a in listaDeTest.PartenerName
where a == s
select a).FirstOrDefault();
if (x == null)
{
<input type="checkbox" name="chkpart @i" />
}
else
{
<input type="checkbox" name="chkpart @i" checked="checked"/>
}
}
else
{
<input type="checkbox" name="chkpart @i" />
}
</td>
<td>
<p style="margin-left: 5px;">@s</p>
</td>
</tr>
….
at then end a have a button with onclick function.
Any ideas what might be? Because in IE works perfectly. Thanks in advance
Internet Explorer and Chrome automatically make global variables for DOM elements with “id” values. Firefox doesn’t, because no standard says it should (and it’s a goofy idea anyway).
Thus, in Internet Explorer, having an HTML tag on the page like this:
means that you’ve also got a global variable (a
windowproperty) called “container”, with its value being a reference to the DOM element for that<div>. In Firefox, you don’t. You have to callto get a reference to the DOM element.
It’s not clear in your code what reference Firefox is complaining about; I suspect it’s “dataTable”, which I’m guessing is the id of the
<table>. You didn’t post that however so I’m not sure.edit — oh, and another thing: Internet Explorer, for reasons unknown, returns elements from the
.getElementById()call based on element name. That erroneous behavior is not copied by Firefox or other browsers. Your input elements have a “name” attribute but no “id”.