Results 1 to 5 of 5

Thread: JavaScript

  1. #1
    Join Date
    Dec 2011
    Posts
    257
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default JavaScript

    Hello I'm looking to create a JavaScript function of sorts that does this:

    Code from www.w3schools.com, it's not my own
    HTML Code:
    (time<10)
      {
      x="Good morning";
      }
    else if (time<20)
      {
      x="Good day";
      }
    else
      {
      x="Good evening";
      }
    I will add the JavaScript tags. I would like it to when the user visits the page the function "plays". How would I go about this please?

    Thankyou.

  2. #2
    Join Date
    Jan 2009
    Location
    Turlock/LA, California
    Posts
    1,494
    Mentioned
    3 Post(s)
    Quoted
    66 Post(s)

    Default

    Code:
    $(document).ready(function () {}
    that might just be for Jquery. but either way, i would recommend you use it.

    Homepage - http://jquery.com/
    Decent beginner tut - http://docs.jquery.com/Tutorials:Get...ed_with_jQuery
    Last edited by x[Warrior]x3500; 09-21-2012 at 04:41 PM.

  3. #3
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Created something for you. Don't use jquery, it is very bad and complete shit. Don't use javascript either, it is also very bad and also quite shitty.

    http://ancientbb.com/tadatada.html

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
       <head> 
          <title>Your test page</title>
      </head>
      
      <body>
         <div id="testDiv">
           hallo
        </div>
        <script src="/yourScript.js" type="text/javascript"></script>
      </body>
    
    </html>
    javascript Code:
    document.getElementById("testDiv").innerHTML = 'bye';

    var timer = 0;

    function timerFunc() {
      timer  = timer + 1;
      var x = "error";
       
      if(timer<10)
      {
      x="Good morning";
      }
    else if (timer<20)
      {
      x="Good day";
      }
    else
      {
      x="Good evening";
      }
     
      document.getElementById("testDiv").innerHTML = 'tada: ' + x;
     
      setTimeout('timerFunc()',100);  // wait 100 ms before recalling this function
    }

    timerFunc();

    e:
    SetInterval would be a nicer solution.
    Last edited by masterBB; 09-21-2012 at 05:31 PM.
    Working on: Tithe Farmer

  4. #4
    Join Date
    Dec 2011
    Posts
    257
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by x[Warrior]x3500 View Post
    Code:
    $(document).ready(function () {}
    that might just be for Jquery. but either way, i would recommend you use it.

    Homepage - http://jquery.com/
    Decent beginner tut - http://docs.jquery.com/Tutorials:Get...ed_with_jQuery
    Quote Originally Posted by masterBB View Post
    Created something for you. Don't use jquery, it is very bad and complete shit. Don't use javascript either, it is also very bad and also quite shitty.

    http://ancientbb.com/tadatada.html

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
       <head> 
          <title>Your test page</title>
      </head>
      
      <body>
         <div id="testDiv">
           hallo
        </div>
        <script src="/yourScript.js" type="text/javascript"></script>
      </body>
    
    </html>
    javascript Code:
    document.getElementById("testDiv").innerHTML = 'bye';

    var timer = 0;

    function timerFunc() {
      timer  = timer + 1;
      var x = "error";
       
      if(timer<10)
      {
      x="Good morning";
      }
    else if (timer<20)
      {
      x="Good day";
      }
    else
      {
      x="Good evening";
      }
     
      document.getElementById("testDiv").innerHTML = 'tada: ' + x;
     
      setTimeout('timerFunc()',100);  // wait 100 ms before recalling this function
    }

    timerFunc();

    e:
    SetInterval would be a nicer solution.
    Thankyou for the replies I'll have a look at the tutorial when I have time. And masterBB, could you make the folder then upload it so I can see a working example please? Because I can't get it to work for some reason (I don't know any JS or jQuery or anything like that.

  5. #5
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    I posted the working example. It just that link.
    Working on: Tithe Farmer

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
  •