Loading ...
Sorry, an error occurred while loading the content.

Any JavaScripters?

Expand Messages
  • Wayland_B_Fowler@Raytheon.com
    Hi NTP HTMLers, Do we have any Java Scripters out there? I am having a small difficulty with a for loop within a function. It seems to loop, just fine, if
    Message 1 of 1 , Jul 17, 2001
    • 0 Attachment
      Hi NTP HTMLers,

      Do we have any Java Scripters out there?

      I am having a small difficulty with a "for loop" within a function. It
      seems to loop, just fine, if the function is invoked directly within the
      BODY of my HTML code, Like the following:

      <SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
      <!-- Hide script from old browsers
      function plugInLoop() {
      for (i = 0; i < navigator.plugins.length; i++) {
      document.write(1 + i)
      document.write(". ")
      document.write(navigator.plugins[i].name)
      document.write("<br>")
      }
      }
      // End hiding script from older browsers -->
      </SCRIPT>
      </HEAD>

      <BODY>
      <SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
      <!--
      plugInLoop()
      // -->
      </SCRIPT>
      </BODY>

      *********** end of script example

      Okay, if I take the same function, and invoke after some event, say cliking
      a button, I get a javascript error stating that my index variable (in this
      case "i") is not defined. Here is the code:

      <SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
      <!-- Hide script from old browsers
      function plugInLoop() {
      for (i = 0; i < navigator.plugins.length; i++) {
      document.write(1 + i)
      document.write(". ")
      document.write(navigator.plugins[i].name)
      document.write("<br>")
      }
      }
      // End hiding script from older browsers -->
      </SCRIPT>
      </HEAD>

      <BODY>
      <FORM>
      <INPUT TYPE=BUTTON VALUE="Plugins?" onClick=plugInLoop()>
      </FORM>
      </BODY>


      Can anyone tell me how the "i" becomes undefined, in the second set of
      code? The place that it reports being not defined is
      "document.write(navigator.plugins[i].name)" Any explanations?

      Regards,

      Wayland
      I think everyone should be nice to me, don't you?
    Your message has been successfully submitted and would be delivered to recipients shortly.