Javascript debugging
Author
Discussion

Plotloss

Original Poster:

67,280 posts

300 months

Monday 22nd May 2006
quotequote all
Got a webpage which uses some javascript for ajax type stuff.

Works perfectly well in Firefox and Opera but I get a runtime error in IE.

The error is undefined (handy) and its reporting an error at line 542 char 3

However, it a PHP document that includes the javascript so I dont know which particular piece of javascript its referring to.

Is there anyway to get at the internal document which its rendering the screen from or is there a debugging framework thats better than the version shipped with IE?

polus

4,343 posts

255 months

Monday 22nd May 2006
quotequote all
if you double click on the error icon it will tell you where the error is. And javascript is client side so php has nothing todo with it (unless its auto generating it) but you should be able to work it out from the script...

Plotloss

Original Poster:

67,280 posts

300 months

Monday 22nd May 2006
quotequote all
Yeah, its reporting line 546 in a PHP file thats all of 15 lines long.

The index.php loads other php's which have various instances of javascript embedded in them so its not loading one document with line reference numbers as such.

polus

4,343 posts

255 months

Monday 22nd May 2006
quotequote all
OK, maybe crossed wires, whats on line 546 (and 5 lines above/below) of the client generated script (IE->Edit->Source)?

Unless my brains stopped working (be warned it does this from time to time) the line refers to whats been generated after the PHP binary has executed and therefore the error in IE is a script error.

>> Edited by polus on Monday 22 May 12:42

slapmatt

1,132 posts

252 months

Monday 22nd May 2006
quotequote all
You're better off running the page in a browser, right clicking and doing View Source. Save that file as a .html page and then debug that file. Once you've modified the code you'll need to copy and paste back to your original JavaScript.

Yes, it's a fudge, but JS is a pain to debug at best.

robbieduncan

1,993 posts

266 months

Monday 22nd May 2006
quotequote all
Install Microsofts free script debugger

Plotloss

Original Poster:

67,280 posts

300 months

Monday 22nd May 2006
quotequote all
I'm just looking at that now, does it do javascript as well as vbscript?

Plotloss

Original Poster:

67,280 posts

300 months

Monday 22nd May 2006
quotequote all
Well I've at least found where the problem is (cheers fellas), why its a problem for IE though I have no bloody idea!

Grrrr.

GreenV8S

31,025 posts

314 months

Monday 22nd May 2006
quotequote all
If you can find a way to present your page with the script referrred to externally rather than inlined in the page source, it's much easier to debug because the IE error handler gives you accurate source locations. Having the source level script debugger should make it fairly straight forward to debug, but if you need to have access to the DOM (as opposed to the HTML page source) to see what is going on, you can use various JScript utilities to show it for you. Google is your friend.

DanL

6,589 posts

295 months

Monday 22nd May 2006
quotequote all
When you say the error is "undefined", what is the actual error message? IIRC, IE tends to use the word undefined when you're trying to use a JS method on an object that it doesn't recognise. This would tie in with it working in one browser, and not in another - have you used a method that IE doesn't know? You may have to install some logic to check the browser type, and use one statement or another depending on whether it's IE or not. (Apologies if I’ve just taught you how to suck eggs. )

Dan

Plotloss

Original Poster:

67,280 posts

300 months

Monday 22nd May 2006
quotequote all
Error: Unknown Runtime Error

Its having issue with the following:

this.construct_playlist = function(playlist_obj)
{
var tracks = playlist_obj.getElementsByTagName("track" );
var playlist = $("playlist_content" );

// Init variables
this.list_pltrack = new Array();
this.pl_selection = new Array
// Clear the playlist
playlist.innerHTML = '';

// Enable commands clear and shuffle if we are tracks in the playlist
var enable = tracks.item(0) ? true : false;
this.enable_command('pl-clear','pl-shuffle',enable);

for (var i=0; track = tracks.item(i); i++)
this.construct_track(playlist,track);
};

The error line as stated is the playlist.innerHTML = '';

Works fine in Firefox...

>> Edited by Plotloss on Monday 22 May 13:42

>> Edited by Plotloss on Monday 22 May 13:42

pdV6

16,442 posts

291 months

Monday 22nd May 2006
quotequote all
Does the playlist object not have a specific 'Clear' method?

GreenV8S

31,025 posts

314 months

Monday 22nd May 2006
quotequote all
What is the value of $("playlist_content" ); ?

Plotloss

Original Poster:

67,280 posts

300 months

Monday 22nd May 2006
quotequote all
Ahh, think you maybe onto something there Peter.

In Firefox

Alert(playlist) returns [object HTMLTableSectionElement]

In IE

Alert(playlist) returns [object]