View Full Version : Problem Isolating JS Error on IE

09-15-2011, 07: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 {
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;


if (elt.id.substr(0,11) == "delCitation")

elt.onclick = deleteCitation;


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:

How do I fix this?

Logic Ali
09-15-2011, 08:23 PM
The currently-indicated error is on line 318 of citTable.js:
"createCitation: sourceSel=" + sourceSel);

This suggests that an exception is being thrown. Find out why.

09-15-2011, 10:10 PM
The currently-indicated error is on line 318 of citTable.js:
"createCitation: sourceSel=" + sourceSel);

This suggests that an exception is being thrown. Find out why.

Thank you.

Firstly obviously somewhere along the line the text "alert(" got removed from this line. When I restore that the alert pops up.

The exception was thrown because the named input element "Source0" was not a member of form.elements. The element is created by the following code, which was executed because the selection list is visible on the page:

var tdSource = document.createElement("INPUT");
tdSource.type = "text";
tdSource.name = "Source" + rowNum;
tdSource.size = 50;
tdSource.value = sourceName;
tdSource.readOnly = true;

However this fails because IE does not permit you to set the name attribute of an input element and the way that you have to set the name attribute in IE is not permitted in a W3C compliant browser! Long string of obscene epithets inserted here!

Secondly: How did you identify the failing line? IE7 does not even tell me what FILE the error is in.

Old Pedant
09-15-2011, 11:46 PM
If you use the Microsoft Script Debugger and turn on script debugging (advanced under internet options under tools), it can find the point of error (and what file it is in). It's nowhere near as easy to use or as powerful as FireBug, but it can get you past the rough spots, most of the time.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum