JavaScript Tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • binnyva@hotmail.com

    #1

    JavaScript Tutorial

    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
    Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


    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
    Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


  • Mick White

    #2
    Re: JavaScript Tutorial

    binnyva@hotmail .com wrote:
    [snip][color=blue]
    >
    > 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.[/color]

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

    document.formNa me.elementName (dot notation)
    Mick

    Comment

    • Evertjan.

      #3
      Re: JavaScript Tutorial

      wrote on 12 jan 2005 in comp.lang.javas cript:
      [color=blue]
      > I am writing an interactive tutorial for JavaScript.[/color]
      [color=blue]
      > Is there a way to show an error if the 'eval'
      > command encounters an error?[/color]
      [color=blue]
      > This tutorial is to completely finished[/color]

      How can it be finished, if you still have a question about JS?


      --
      Evertjan.
      The Netherlands.
      (Replace all crosses with dots in my emailaddress)

      Comment

      • Richard Cornford

        #4
        Re: JavaScript Tutorial

        binnyva@hotmail .com wrote:[color=blue]
        > Hello Everybody,
        >
        > I am writing an interactive tutorial for JavaScript.[/color]
        <snip>

        <quote
        cite="http://www.geocities.c om/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.


        Comment

        • rh

          #5
          Re: JavaScript Tutorial

          binnyva@hotmail .com wrote:[color=blue]
          > 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.
          >[/color]

          That's not exactly a new idea, but it has merit nonetheless.
          [color=blue]
          > 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?
          >[/color]

          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.mes sage || e.description ) );'
          /**/ +'}'
          /**/ );
          /*JRS*/

          EVAL(testText);
          </script>[color=blue]
          > You can check out this tutorial at
          >[/color]
          http://www.geocities.com/binnyva/cod...ial/index.html[color=blue]
          >
          > 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.[/color]

          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

          Comment

          Working...