www.webdeveloper.com
Results 1 to 7 of 7

Thread: Dumb A$$ Needs Help

  1. #1
    Join Date
    Sep 2011
    Posts
    3

    Dumb A$$ Needs Help

    I have to be mentally challenged. I am learning Java (after 20+ years doing C and C++) and wrote a simple program to start testing a part of what I want to do ultimately. In the example, the "setInterval" works ONCE (calls function and prints the first array string) and then the browser looks like it's trying to reload the page and nothing happens.

    I have to be doing something incredibly dumb, but all my online hunting was not any help. Can someone set me straight here please? Thanks!

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html><head><title>Test Test</title>
    <script language="JavaScript">
    /*-----declare global stuff---'x' will be used later-----*/ 
       x = 0;
       maxKey = 3;
       keyword = new Array(maxKey);
    
        keyword[ 0]="4u1un";
        keyword[ 1]="ve8at";
        keyword[ 2]="w6wx";
        keyword[ 3]="kh6wo";
    /*-----function to print out array one string at a time incrimenting 'x'-----*/
    function popitout()
    {
       document.write(keyword[x]);
       document.write("<br>");
       x++;
       if (x == maxKey){
          x = 0;
       }
    }
    </script></head>
    <body>
    <br>Some BS text to know page is loaded...<br>
    <script type="text/javascript">
    
    /*-------run the popitout() function every 5 seconds------*/
    var t=setInterval("popitout();", 5000);
    
    </script></body></html>

  2. #2
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,132
    Seems to be working correctly here:
    http://jsfiddle.net/dfreema1/SxSN6/
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  3. #3
    Join Date
    Sep 2011
    Posts
    3
    Thanks cb, which browser do you use? I ran it over the network using Safari and it works as intended. It will not work with Firefox. Firefox displays the first "4UN" variable and then tries to reload the page, just setting there "loading..". So that's two different computers both using Firefox that won't work.

    I appreciate the help. It's basic Javascript. If you substitute the standard javascript example (an alert box) for the function called by "setInterval" it works all day like:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
      <title>Alert Box Example</title>
    </head>
    <body>
    Blah blah blah blah....6 second Marriage Participation Timer....<br>
    <br>
    <br>
    <script type="text/javascript">
    setInterval('alert(\'6 seconds. Wife time is over!\')', 6000);
    </script>
    </div>
    </body>
    </html>

  4. #4
    Join Date
    Mar 2009
    Posts
    501
    This is odd. On firefox it doesn't work (I'm on a Linux box by the way) but on Chrome the code works perfectly.

  5. #5
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,132
    Seems to be related to the document.write. If you output the results in a container using innerHTML it seems to work fine in FF. Here's the updated version:
    http://jsfiddle.net/dfreema1/SxSN6/20/
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  6. #6
    Join Date
    Sep 2011
    Posts
    3
    cb,

    ur the tops, man. Now I will go and study those code lines and see how they work. My humble thanks! And I will name my next child after you too.

    PD

  7. #7
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,132
    Hahahahah, I'm naming my first child after me "Dan" is a great name after all!
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles