www.webdeveloper.com
Results 1 to 5 of 5

Thread: update automatically the sentence in web page everyday

Hybrid View

  1. #1
    Join Date
    Jan 2014
    Posts
    11

    update automatically the sentence in web page everyday

    Hi everyone! I'm not a javascript guy, but I can occasionally edit other code to do what I want and learning as web developer.

    Thus, I'm trying to find code that will load a sentence based on the day (every day). In other words, in each day, I want one line from web page to load, next day as well as it changes to other sentence for example quote by other quote that I wrote a list of 80 different quotes, which will post one everyday.

    I can't find any code that refers to date ranges (without the year), but have seen some using time of day. Can that type of code be altered to fit these parameters? I'd prefer to have the page be a redirect, I guess I can work it into the menu so the correct page loads right away instead of being redirected.

    Anyone have any ideas? Thanks in advance!

  2. #2
    Join Date
    Jul 2013
    Location
    France
    Posts
    15
    hello there,

    Here is a small example :

    Code:
    <!DOCTYPE html>
    <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
    <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    
      <script type="text/javascript">
          $(document).ready(function() {
          var now = new Date();
          var hours = now.getHours();
          var msg;
          if (hours < 12) msg = "Good Morning";
          else if (hours < 18) msg = "Good Afternoon";
          else msg = "Good Evening";
          $('#time p').text(msg);
        });
    });
    </script>
    
    </head>
    
    <body>
    
    <div class="container">
        <div id="time">
            <p>Good morning.</p>
        </div>
    
    <div>
        <p>My Message<br>My message 2.<br> My quote.</p>
    </div>
    </div>
    
    </body>
    
    </html>
    This is based on morning, evening.. but you can adapt it.. for more information :

    http://api.jquery.com/text/

    Goodluck

  3. #3
    Join Date
    Jan 2014
    Posts
    11

    Question

    I looked at this code that made me confused because it talks about hours.
    So, I'm trying to change the code to see if it right code for days not hours

    <script type="text/javascript">
    $(document).ready(function()
    {
    var now = new Date();
    var days = now.getHours();
    var msg;
    if (days < 1) msg = How do you feel?";
    else if (days < 2) msg = "Don't forget to do routine!";
    else msg = "God Bless you!";
    $('#time p').text(msg);
    });
    });
    </script>

    I wonder why I see repeated 2 times }); in the code? Do I have to delete }); at once?

  4. #4
    Join Date
    Jan 2014
    Posts
    11
    Thank deadmix!
    I will follow your code and modify to see if it work then I will let you to know :-D

  5. #5
    Join Date
    Jul 2013
    Location
    France
    Posts
    15
    hello there,

    delete the second }); and check again!

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