www.webdeveloper.com
Results 1 to 9 of 9

Thread: Box content changes by refresh?

  1. #1
    Join Date
    Aug 2013
    Posts
    56

    Question Box content changes by refresh?

    Hello,

    I want the code for a simple box with content.

    When someone refresh the page the content changes.

    It must fit in a html document, so with a script element.

    Thanks for reading,

    Niely,

  2. #2
    Join Date
    Oct 2012
    Posts
    78
    Code:
    <html>
    <head>
    <script type="text/javascript">
      var ran = [
           "Hellllo"
         , "Goodbyeee"
         , "Welcome Backkkk"
      ];
      function displayText() {
        var para = '<p>';
        var randomIndex = Math.floor(Math.random() * ran.length);
        para += ran[randomIndex];
    	para += '</p>';
        return para;
      }
    </script>
    </head>
    <body>
    <script type="text/javascript">
      document.write(displayText());
    </script>
    </body>
    </html>
    Found this a while back and edited for my needs at the time. It just loads random content when people refresh/load the page.
    Last edited by theyoker; 08-24-2013 at 03:53 PM.

  3. #3
    Join Date
    Aug 2013
    Posts
    56
    Quote Originally Posted by theyoker View Post
    Code:
    <html>
    <head>
    <script type="text/javascript">
      var ran = [
           "Hellllo"
         , "Goodbyeee"
         , "Welcome Backkkk"
      ];
      function displayText() {
        var para = '<p>';
        var randomIndex = Math.floor(Math.random() * ran.length);
        para += ran[randomIndex];
        return para;
      }
    </script>
    </head>
    <body>
    <script type="text/javascript">
      document.write(displayText());
    </script>
    </body>
    </html>
    Found this a while back and edited for my needs at the time. It just loads random content when people refresh/load the page.
    Whoow thanks!!! D

    If I want to add something I just need to add it between "tags?"?

  4. #4
    Join Date
    Aug 2013
    Posts
    56
    OMG!! Thanks you so much!
    You're awesome! D

  5. #5
    Join Date
    Oct 2012
    Posts
    78
    Im guessing you found how to add stuff. Need anything else just ask.

    PLEASE USE THE CODE BELOW. As the code above dosen't close the <p> tag, which will cause you problems later on.
    Code:
    <html>
    <head>
    <script type="text/javascript">
      var ran = [
           "Hellllo"
         , "Goodbyeee"
         , "Welcome Backkkk"
      ];
      function displayText() {
        var para = '<p>';
        var randomIndex = Math.floor(Math.random() * ran.length);
        para += ran[randomIndex];
    	para += '</p>';
        return para;
      }
    </script>
    </head>
    <body>
    <script type="text/javascript">
      document.write(displayText());
    </script>
    </body>
    </html>
    Last edited by theyoker; 08-24-2013 at 03:48 PM.

  6. #6
    Join Date
    Aug 2013
    Posts
    56
    Quote Originally Posted by theyoker View Post
    Im guessing you found how to add stuff. Need anything else just ask.

    PLEASE USE THE CODE BELOW. As the code above dosen't close the <p> tag, which will cause you problems later on.
    Code:
    <html>
    <head>
    <script type="text/javascript">
      var ran = [
           "Hellllo"
         , "Goodbyeee"
         , "Welcome Backkkk"
      ];
      function displayText() {
        var para = '<p>';
        var randomIndex = Math.floor(Math.random() * ran.length);
        para += ran[randomIndex];
    	para += '</p>';
        return para;
      }
    </script>
    </head>
    <body>
    <script type="text/javascript">
      document.write(displayText());
    </script>
    </body>
    </html>
    That code doesn't work.

  7. #7
    Join Date
    Aug 2013
    Posts
    56
    I got another question.

    I want your java code in a HTML/CSS DIV box, how do I fix that? :P

  8. #8
    Join Date
    Oct 2012
    Posts
    78
    Edit, No the code above directly pasted works in all browsers. I just had active turned off in I.E.

    I assume you mean that sort of thing about a DIV. Post the code you trying to get working makes it easier for me.

    Code:
    <html>
    <head>
    <script type="text/javascript">
      var ran = [
           "Hellllo"
         , "Goodbyeee"
         , "Welcome Backkkk"
      ];
      function displayText() {
        var para = '<p>';
        var randomIndex = Math.floor(Math.random() * ran.length);
        para += ran[randomIndex];
    	
        return para;
      }
    </script>
    </head>
    <body>
    <div id="css">
    <script type="text/javascript">
      document.write(displayText());
    </script>
    </div>
    </body>
    </html>
    Last edited by theyoker; 08-24-2013 at 04:18 PM.

  9. #9
    Join Date
    Aug 2013
    Posts
    56
    OMG! It's 100% ready!!
    Thanks you so much! D

Thread Information

Users Browsing this Thread

There are currently 4 users browsing this thread. (0 members and 4 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