/    Sign up×
Community /Pin to ProfileBookmark

tips on debugging JavaScript errors

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

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@VladdyJul 06.2004 — Use mozilla for intial script development.
Copy linkTweet thisAlerts:
@steelersfan88Jul 06.2004 — 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:<i>
</i>1 &lt;title&gt;My title&lt;/title&gt;
2 &lt;script type="text/javascript"&gt;
3 var str = "string"
4 var num = 1
5 var arr = new Array()
6 function dosomething() {
7 }
8 &lt;/script&gt;
9 &lt;form name="myform"&gt;
10 &lt;/form&gt;
(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
×

Success!

Help @davidklonski spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...