/    Sign up×
Community /Pin to ProfileBookmark

how do i prevent from errours to accure?q

say i have error like this :
document.myTextBox.value object not found or dont xist
how can i catch this error and tell the user what was the problem?
thnaks in advance
peleg

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@JonaJun 01.2004 — [i]Originally posted by pelegk1 [/i]

[B]

document.myTextBox.value object not found or dont xist

[/B]
[/QUOTE]


<i>
</i>&lt;script type="text/javascript"&gt;
/* Goes in head tag */

window.onerror = myOnError;
msgArray = new Array();
urlArray = new Array();
lnoArray = new Array();
function myOnError(msg, url, lno) {
msgArray[msgArray.length] = msg;
urlArray[urlArray.length] = url;
lnoArray[lnoArray.length] = lno;
return true;
}
function displayErrors() {
win2=window.open('','window2','scrollbars=yes');
win2.document.writeln('&lt;B&gt;Error Report&lt;/B&gt;&lt;P&gt;');
for (var i=0; i &lt; msgArray.length; i++) { win2.document.writeln('&lt;B&gt;Error in file:&lt;/B&gt;'+urlArray[i]+'&lt;BR&gt;');
win2.document.writeln('&lt;B&gt;Line number:&lt;/B&gt;'+lnoArray[i]+'&lt;BR&gt;');
win2.document.writeln('&lt;B&gt;Message:&lt;/B&gt;'+msgArray[i]+'&lt;P&gt;');
}
win2.document.close()
}
&lt;/SCRIPT&gt;


[font=arial]After installing the above code in your head tag, create two buttons. One that generates an error, and one that calls the displayErrors() function (onclick="displayErrors()"). Click the button that generates an error, then click the button that displays the errors.

Notice: This script was created by Netscape. I found it a very long time ago, and don't remember where on Netscape's Web site I found it.[/font]
Copy linkTweet thisAlerts:
@JonaJun 02.2004 — [font=arial]Yes - can you not test it on your own, though?[/font]
Copy linkTweet thisAlerts:
@pelegk1authorJun 10.2004 — but a window isnt opening why?

thnaks in advance

peleg
Copy linkTweet thisAlerts:
@JonaJun 12.2004 — <i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/transitional.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
&lt;title&gt;Window.onError&lt;/title&gt;
&lt;SCRIPT type="text/javascript"&gt;
window.onerror = myOnError
msgArray = new Array()
urlArray = new Array()
lnoArray = new Array()
function myOnError(msg, url, lno) {
msgArray[msgArray.length] = msg
urlArray[urlArray.length] = url
lnoArray[lnoArray.length] = lno
return true;
}
function displayErrors() {
win2=window.open('','window2','scrollbars=yes');
win2.document.writeln('&lt;B&gt;Error Report&lt;/B&gt;&lt;P&gt;');
for (var i=0; i &lt; msgArray.length; i++) { win2.document.writeln('&lt;B&gt;Error in file:&lt;/B&gt;'+urlArray[i]+'&lt;BR&gt;');
win2.document.writeln('&lt;B&gt;Line number:&lt;/B&gt;'+lnoArray[i]+'&lt;BR&gt;');
win2.document.writeln('&lt;B&gt;Message:&lt;/B&gt;'+msgArray[i]+'&lt;P&gt;');
}
win2.document.close()
}
&lt;/SCRIPT&gt;&lt;/head&gt;
&lt;BODY onload="noSuchFunction()"&gt;
&lt;FORM action=""&gt;&lt;div&gt;
&lt;INPUT TYPE="button" VALUE="This button has a syntax error" onClick="alert('unterminated string)"&gt;
&lt;INPUT TYPE="button" VALUE="Display Error Report" onClick="displayErrors()"&gt;
&lt;/div&gt;&lt;/FORM&gt;
&lt;/body&gt;&lt;/html&gt;
Copy linkTweet thisAlerts:
@pelegk1authorJun 13.2004 — and fro, pressing on both buttons the only thing that have happend is :

a new indow was opened with the only line

"Error in file"
Copy linkTweet thisAlerts:
@JonaJun 13.2004 — [i]Originally posted by pelegk1 [/i]

[B]and fro, pressing on both buttons the only thing that have happend is :

a new indow was opened with the only line

"Error in file" [/B]
[/QUOTE]


[font=arial]Works for me in every browser I've tested it in. Are you on a Mac? It might not work on a Mac.[/font]
×

Success!

Help @pelegk1 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,
)...