user1703145 user1703145 - 20 days ago 5
Javascript Question

document.all is not working in Firefox

I am working on an old project for maintenance. I found that

document.all
is not working in firefox 25. and I am getting the error below.

TypeError: document.all.TabularDataControlAttivitta.object is undefined


and my sample code is

document.all.TabularDataControlProj.object.Filter = 'COMPANYCODE=' + compValue;
document.all.TabularDataControlProj.object.Reset();
document.getElementById('cmbActivity_' + rowNo).options.length = 1;
if (document.getElementById('cmbProject_' + rowNo).options.length > 0) {
for (var i = document.getElementById('cmbProject_' + rowNo).options.length - 1; i >= 0; i--) {
document.getElementById('cmbProject_'+rowNo).options[i] = null;
}
}
if (document.all.TabularDataControlProj.recordset.recordcount > 0) {
document.all.TabularDataControlProj.recordset.movefirst;
}
pOption = new Option('-Select-', -1);
document.getElementById('cmbProject_' + rowNo).add(pOption);
while (document.all.TabularDataControlProj.recordset.eof == false) {
Optionp = new Option((document.all.TabularDataControlProj.recordset.fields(0) + ' - ' + document.all.TabularDataControlProj.recordset.fields(2)), document.all.TabularDataControlProj.recordset.fields(0));
document.getElementById('cmbProject_' + rowNo).add(Optionp);
document.getElementById('cmbProject_' + rowNo).selectedIndex = indxAct;
document.all.TabularDataControlProj.recordset.movenext;
}
}


Any patch or solution for this? Because it's very difficult to edit the entire project.

Answer

document.all is non-standard. It was a Microsoft-specific feature that they added to IE. Most other browsers have never supported it.

Even in IE it is now deprecated. You should not be using it.

(your old project must be very old, because this has been the case for quite some time now)

For most cases, you can use document.getElementById() instead.

If you're using document.all to get an element using it's ID value then document.getElementById() is a direct replacement.

If you're using document.all to get an element some other way, then I recommend switching to getting it by ID (add an ID if necessary).

I note that the way you're using the element makes it look like it may be an activeX control? (ie I see stuff like .object.Filter, .recordset.movefirst, etc)

If that is the case, then you need to be aware that Firefox does not support activeX controls at all. They are also specific to IE. If it is an activeX control and you need it to work in Firefox then unfortunately, you probably have quite a lot of rewriting ahead of you.