By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,870 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,870 IT Pros & Developers. It's quick & easy.

JavaScript Tutorial

P: n/a
Hello Everybody,

I am writing an interactive tutorial for JavaScript.
I created a text box into which the users can input
javascript commands. On pressing a button, these commands
will be evaluated.

It works fine - but won't show any error if the commands
are wrong. Is there a way to show an error if the 'eval'
command encounters an error?

You can check out this tutorial at
http://www.geocities.com/binnyva/cod...ial/index.html

This tutorial is to completely finished - so if you have any
suggetions/comments please let me know. If you think that I
have left out something important please send me a note
and I will see to the problem.
Thanks in Advance,
Binny V A
http://www.geocities.com/binnyva

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
bi*****@hotmail.com wrote:
[snip]

You can check out this tutorial at
http://www.geocities.com/binnyva/cod...ial/index.html

This tutorial is to completely finished - so if you have any
suggetions/comments please let me know. If you think that I
have left out something important please send me a note
and I will see to the problem.


You know that it works only in IE Windows?
You may want to learn how to reference a form control.

document.formName.elementName (dot notation)
Mick
Jul 23 '05 #2

P: n/a
wrote on 12 jan 2005 in comp.lang.javascript:
I am writing an interactive tutorial for JavaScript. Is there a way to show an error if the 'eval'
command encounters an error? This tutorial is to completely finished


How can it be finished, if you still have a question about JS?
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #3

P: n/a
bi*****@hotmail.com wrote:
Hello Everybody,

I am writing an interactive tutorial for JavaScript.

<snip>

<quote
cite="http://www.geocities.com/binnyva/code/javascript/basic_tutorial/va
riables.html">
JavaScript is a loose typing language. So you don't have to declare the
variables. But there is an option to do so. Use 'var' in front of the
variable you wish to declare - but you can leave that out if you don't
wish to work you fingers unnecessary.
</quote>

Tutorial or practical joke?

Richard.
Jul 23 '05 #4

P: n/a
rh
bi*****@hotmail.com wrote:
Hello Everybody,

I am writing an interactive tutorial for JavaScript.
I created a text box into which the users can input
javascript commands. On pressing a button, these commands
will be evaluated.

That's not exactly a new idea, but it has merit nonetheless.
It works fine - but won't show any error if the commands
are wrong. Is there a way to show an error if the 'eval'
command encounters an error?

If the user of your tutorial is running a modern browser, one that
supports the ECMA-262 Javascript standard, you can use the try-catch
constructs of the language to provide infomation about errors that may
occur during execution.

The problem is that not everyone runs up-to-date browsers, and
inclusion of try-catch will cause syntax errors when encountered in the
older browsers. The following example may provide a way to capture
errors in most browsers without causing syntax error grief in browsers
that don't support try-catch :

(/**/ prefixes the lines in order to maintain code formatting in this
posting)

<script type="text/javascript">
/*JRS*/
/**/ var checkTry = "try {}catch(e){}";
/**/ var testText = "This cannot be successfully executed!";

/**/ var EVAL;

/**/ var ahhFutz = function() { // try/catch is not available
/**/ EVAL = function (code) { eval(code) };
/**/ window.onerror = function(msg) { // Output message on error
/**/ alert( "Execution failed: "+msg);
/**/ }
/**/ // Wait for an event
/**/ }

/**/ window.onerror = ahhFutz;
/**/ eval (checkTry); // See if try/catch is available

/**/ EVAL = new Function("code", // try/catch is available, so use it
/**/ 'try { '
/**/ +' eval(code); '
/**/ +'} '
/**/ +'catch (e) {'
/**/ +' alert( "Execution failed for :"+code+'
/**/ +' "\\n\\n"+(e.message || e.description ) );'
/**/ +'}'
/**/ );
/*JRS*/

EVAL(testText);
</script> You can check out this tutorial at
http://www.geocities.com/binnyva/cod...ial/index.html
This tutorial is to completely finished - so if you have any
suggetions/comments please let me know. If you think that I
have left out something important please send me a note
and I will see to the problem.


I like the humerous approach in the tutorial. However, as pointed out
in earlier posts, it appears that you have some learning and work to do
yet (as an example, note that the ++ and -- operators can be both
prefix and postfix, and may have considerably different effects
depending on their placement relative to the operand).

../rh

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.