Results 1 to 5 of 5

Thread: Why must I wrap these calls in a function?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Okay, I have two pages. One works in Navigator, the other doesn't. They both work in IE. Would you guys look them over and tell me what is wrong?

    Code:
    <head>
    
    <script language='JavaScript' src='DynEl.js'></script>
    
    <script language='JavaScript'>
    
      var table1 = " "
      var table2 = "More test text"
    
      var dynel1 = new DynEl(window, "d1", table1);
      var dynel2 = new DynEl(window, "d2", table2);
    
    </script>
    
    </head>
    
    <body onload='JavaScript:Init();'>
    
    <a href="JavaScript:Toggle('1');">Show 1</a>
    <a href="JavaScript:Toggle('2');">Show 2</a>
    
    <script language='JavaScript'>
      dynel1.output();
      dynel2.output();
    
      // In Navigator these two lines do not 
      //appear to have been executed
      dynel1.setBody("blah");
      dynel1.setBody("foo", "bar");
    </script>
    
    <script language='JavaScript'>
    
      function Init() {
        Toggle('1');
      }
    
      function Toggle(index) {
    
        index = parseInt(index);
    
        dynel1.hide();
        dynel2.hide();
    
        if (index == 1) {
          dynel1.show();
        }
        else if (index == 2) {
          dynel2.show();
        }
    
      }
    
    </script>
    
    </body>
    Code:
    <head>
    
    <script language='JavaScript' src='DynEl.js'></script>
    
    <script language='JavaScript'>
    
      var table1 = " "
      var table2 = "More test text"
    
      var dynel1 = new DynEl(window, "d1", table1);
      var dynel2 = new DynEl(window, "d2", table2);
    
    </script>
    
    </head>
    
    <body onload='JavaScript:Init();'>
    
    <a href="JavaScript:Toggle('1');">Show 1</a>
    <a href="JavaScript:Toggle('2');">Show 2</a>
    
    <script language='JavaScript'>
      dynel1.output();
      dynel2.output();
    
      //But if I wrap these lines in a function
      //and use an event to call that function... it work
      function doRun() {
        dynel1.setBody("blah");
        dynel1.setBody("foo", "bar");
      }
    
    </script>
    
    <script language='JavaScript'>
    
      function Init() {
        Toggle('1');
    
        doRun();
    
      }
    
      function Toggle(index) {
    
        index = parseInt(index);
    
        dynel1.hide();
        dynel2.hide();
    
        if (index == 1) {
          dynel1.show();
        }
        else if (index == 2) {
          dynel2.show();
        }
    
      }
    
    </script>
    
    </body>
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Attached is the JavaScript source included in the head, it is from the Rhino book, and is not at fault.
    Attached Files Attached Files
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  3. #3
    Addicted Member Active's Avatar
    Join Date
    Jan 2001
    Location
    Lat: 13° 4' 46" N, Long: 80° 15' 20" E
    Posts
    209
    Code:
    <body onload='java script:Init();'>
    
    <a href="java script:Toggle('1');">Show 1</a>
    <a href="java script:Toggle('2');">Show 2</a>
    why is there a space between java and script ?
    It should be javascript !
    If you can't beat your computer at chess, try kickboxing !!!
    [Download Tag Editing Tools.]

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Odd... I didn't put the spaces there.

    Mmm... let me try this...

    Code:
    <a href="JavaScript:Toggle('1');">Show 1</a>
    <a href="JavaScript:Toggle('2');">Show 2</a>
    <a href="JavaScript:Toggle('1');">Show 1</a>
    <a href="JavaScript:Toggle('2');">Show 2</a>


    -------

    Cool, this site breaks up JavaScipt and changes the case so each time I get java script.

    Ask the admin why. I'm guess it is so it doesn't get interpreted by your browser.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  5. #5
    Addicted Member Active's Avatar
    Join Date
    Jan 2001
    Location
    Lat: 13° 4' 46" N, Long: 80° 15' 20" E
    Posts
    209
    oooh...that's a Bug,, Post it in the forum feedback !!
    If you can't beat your computer at chess, try kickboxing !!!
    [Download Tag Editing Tools.]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width