jcobban
09-15-2011, 06:57 PM
I have a script that works fine on Firefox but fails with an "Object expected" error on IE7. Frustratingly IE will not tell me where the error is. It reports a line number and the URL of the invoking page, but does not identify in which actual JS file the problem occurred.
I narrowed down that the problem was occurring in a call to a particular function. I did this by wrapping a try/catch around the call:
try {
initCit();
}
catch(e) {
alert("editEvent.js: loadEdit: error=" + e.message);
}
Then I wrapped a try catch around the entire contents of the function initCit:
function initCit()
{
try {
var citTable = document.getElementById('citTable');
citTable.updateRow = updateRow; // feedback from editCitation.php
var form = citTable.parentNode;
while(form.nodeName != 'FORM')
form = form.parentNode;
// define onclick handlers for some elements
var formElts = form.elements;
for (var i = 0; i < formElts.length; ++i)
{ // loop through elements
var elt = formElts[i];
if (elt.id.substr(0,12) == "editCitation")
elt.onclick = editCitation;
else
if (elt.id.substr(0,11) == "delCitation")
elt.onclick = deleteCitation;
else
if (elt.id == "addCitation")
elt.onclick = addCitation;
} // loop through elements
} catch (e) {
alert("citTable.js: initCit: error" + e.message);
} // catch
} // initCit
The outer try/catch is the only one that catches. Furthermore if I add an alert as the first line of the function initCit it is not displayed.
To observe an example of this go to:
http://www.jamescobban.net/FamilyTree/editEvent.php?ider=300&type=30
How do I fix this?
I narrowed down that the problem was occurring in a call to a particular function. I did this by wrapping a try/catch around the call:
try {
initCit();
}
catch(e) {
alert("editEvent.js: loadEdit: error=" + e.message);
}
Then I wrapped a try catch around the entire contents of the function initCit:
function initCit()
{
try {
var citTable = document.getElementById('citTable');
citTable.updateRow = updateRow; // feedback from editCitation.php
var form = citTable.parentNode;
while(form.nodeName != 'FORM')
form = form.parentNode;
// define onclick handlers for some elements
var formElts = form.elements;
for (var i = 0; i < formElts.length; ++i)
{ // loop through elements
var elt = formElts[i];
if (elt.id.substr(0,12) == "editCitation")
elt.onclick = editCitation;
else
if (elt.id.substr(0,11) == "delCitation")
elt.onclick = deleteCitation;
else
if (elt.id == "addCitation")
elt.onclick = addCitation;
} // loop through elements
} catch (e) {
alert("citTable.js: initCit: error" + e.message);
} // catch
} // initCit
The outer try/catch is the only one that catches. Furthermore if I add an alert as the first line of the function initCit it is not displayed.
To observe an example of this go to:
http://www.jamescobban.net/FamilyTree/editEvent.php?ider=300&type=30
How do I fix this?