Javascript tidbits
Results 1 to 3 of 3

Thread: Javascript tidbits

  1. #1
    Banned
    Join Date
    Sep 2001
    Posts
    69

    Post Javascript tidbits

    I am posting this to help people and to gain point (hopefully ). I am on the abomitable list of the close to being banned for my low points. These are a creditted to my willingness to jump into controversial forums and state my own ideas, and my laziness in posting often or start useful threads. I can not call this a tutorial as it does not teach you haw to program fluently in javascript. I only am stating a useful instance and my date script for people to copy.

    How many times have you wanted to state something when someone clicked a button, but you did not want to load a whole 'nother page just to say a sentence or two. Here are a few ways to do it:

    If you want to use alerts here is how to go about it:
    Code:
    <FORM>
    <INPUT type="button" value="next" onClick='alert("The password is FRED ")'>
    </FORM>
    What would happen if you wanted to include quotation marks in your alert? You could do it like this:

    Code:
    <SCRIPT language="JavaScript">
    var message = 'Whatever" you" wanted" to "appear in the alert';
    </SCRIPT>
    <FORM>
    <INPUT type="button" value="next" onClick='alert(message)'>
    </FORM>
    Sometimes alerts are not the answer since no html can be add to one. This can have many uses:

    Code:
    <SCRIPT language="JavaScript">
    var message = 'Whatever you wanted to appear in the on the page including <H1>html</H1>';
    </SCRIPT>
    <FORM>
    <INPUT type="button" value="next" onClick='document.write(message)'>
    </FORM>
    The above code clears the page and prints whatever you type in the message section! It's like having another html page!

    I will finish up with one last script. I created it, and the code is not the neatest, but I think it will be of some use. It prints out the current date in the follow ing form:
    ie:
    Today is: June, 2002
    Friday the 7th

    Here is the code, paste it where you want the date to be displayed:

    Code:
    <SCRIPT language="JavaScript">
    <!-- 
    dayname = new Array("Null", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
    monthname = new Array ("January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
    ending = new Array("st", "nd", "rd", "th")
    var time = new Date()
    var timey = time.getYear()
    var timed = time.getDay()
    var timem = time.getMonth()
    var timed = time.getDate()
    var nof = time.getDay()
    var nof = nof + 1
    if(timey < 1000){
       timey += 1900
       }
      if (timed == 1 || timed == 21 || timed == 31){
         var ender = ending[0]
         }
         else{
              if (timed == 2 || timed == 22){
              var ender = ending[1]
              }
              else{
                  if (timed == 3 || timed == 23){
                  var ender = ending[2]
                  }  
                  else {
                       var ender = ending[3]
                       }
                  }
              }     
    document.write("Today is: " + monthname[timem] + ", "
    + timey + "
    " + dayname[nof] + " the " + timed + ender)
    //-->
    </SCRIPT>
    Well that raps it up for now. Please do not bash me to bad for the sloppiness of the code. I may post more in the future. I hope you can use these examples. If you are interested in learning javascript, please check out this site. It is the best free tutorial I know about.
    http://www.javascriptmall.com/learn/contents.htm.

  2. #2
    Junior Member
    Join Date
    Jun 2002
    Posts
    6
    Bumping UP, I couldn't see a JS tutorial go down in flames like this

  3. #3
    Senior Member
    Join Date
    Nov 2001
    Location
    Ireland
    Posts
    735
    You did a lot of fux0ring about when you were trying to get the year. Maybe this might help.
    Code:
    <script language="JavaScript">
    var time = new Date();
    var year = time.getFullYear();
    alert(year);
    </script>
    Just a thought.

Posting Permissions

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