Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2011
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Problem Isolating JS Error on IE

    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:
    Code:
        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:
    Code:
    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/FamilyTre...er=300&type=30

    How do I fix this?

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    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.
    Last edited by Logic Ali; 09-15-2011 at 07:27 PM.

  • Users who have thanked Logic Ali for this post:

    jcobban (09-15-2011)

  • #3
    New Coder
    Join Date
    Mar 2011
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Logic Ali View Post
    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:
    Code:
    	var tdSource		= document.createElement("INPUT");
    	tdSource.type		= "text";
    	tdSource.name		= "Source" + rowNum;
    	tdSource.size		= 50;
    	tdSource.value		= sourceName;
    	tdSource.readOnly	= true;
    	td2.appendChild(tdSource);
    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.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •