Click to See Complete Forum and Search --> : tips on debugging JavaScript errors


davidklonski
07-06-2004, 05:32 PM
Hello

I am new to JavaScript.
I am using IE6.

Every now and then I get JavaScript errors in my pages and I find it very difficult to find the location of the error.

I get a message saying that the error is in file: x.php on line 5, where in fact the error turns out to be in test.js on line 20!
of course I include test.js in x.php but IE doesn't know how to give the right file and line for the error!

Is there a simple and preferred way to debug such errors and get to the right file and line?

thanks

Vladdy
07-06-2004, 05:34 PM
Use mozilla for intial script development.

steelersfan88
07-06-2004, 05:38 PM
IE provides errors as if the .js file was included on the page by the server. The following example:<!-- test.js -->
1 var str = "string"
2 var num = 1
3 var arr = new Array()
4 function dosomething() {
5 }
<!-- End test.js -->

<!-- End test.htm -->
1 <title>My title</title>
2 <script src="test.js" type="text/javascript">
3 </script>
4 <form name="myform">
5 </form>
<!-- End test.htm -->is read in IE generally as:
1 <title>My title</title>
2 <script type="text/javascript">
3 var str = "string"
4 var num = 1
5 var arr = new Array()
6 function dosomething() {
7 }
8 </script>
9 <form name="myform">
10 </form>(Note that it might read lines 2 and 3 as 1 line, and have a total of 10 .. not sure.

Its incredibly tough to do php errors since files are included, so looking at the source is dif't fro mthe code you have ...

Dr. Script