Web Hosting How-Tos

  Home arrow Web Hosting How-Tos arrow Page 3 - Building a CMS
Web Hosting Articles  
Web Hosting FAQs  
Web Hosting How-Tos  
Web Hosting News  
Web Hosting Reviews  
Web Hosting Security  
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WEB HOSTING HOW-TOS

Building a CMS
By: Chris Root
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 22
    2005-01-05

    Table of Contents:
  • Building a CMS
  • An Outline
  • The Application
  • Object Oriented Code
  • Constructing the Main Heading Markup

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     

    SEARCH WEB HOSTERS

    TOOLS YOU CAN USE

    advertisement

    Building a CMS - The Application


    (Page 3 of 5 )

    In this case we aren't submitting the form to the server; the markup is being generated and then displayed in another window. There are no real Javascript bells and whistles here -- just form processing. You of course should always make an effort to make your applications accessible. As this is an application and likely to be running on an intranet not used by the general public, it is expected that the browser in question has Javascript enabled. There are other development platforms that could be used for this sort of application, however distributing and maintaining proprietary standalone applications on a company network has its disadvantages. It is likely that every desktop that needs this application has a Web browser, so doing this within a browser is the best solution.

    The Code

    One of the features of our press release generator application is to display the current date and time. Javascript has a pre-built object for this that we should walk through for the benefit of those that have not used it before.

    The Javascript date object has quite a few methods available for getting date information and for formatting existing dates and times. For this purpose however we only need five of these methods. The getFullYear() method retrieves the full Y2K compliant year in four digit format (ie. 2005 as of this writing), the getMonth() method which retrieves the numerical month, the getDate() method which retrieves the day of the month, the getHours() method which retrieves the hours in 24 hour format (0-23) and the getMinutes() method that retrieves the minutes.

    We're not done once these values are stored however. If we want to display the date and time in a format that looks like the date below,

    we will have to do some work on the numbers and add some text such as the "PM" to get what we need. The code below will get and display the date and time in this format. It can be called on document load. The form's name is set to release and each field is named year, month, day and hours respectively.

    //Begin our function
    function getdate()
    {
       var curr_dt = new Date();//create a new date object
       //get the year, convert it to a string and then extract the last two characters
       document.release.year.value = curr_dt.getFullYear().toString().substr(2,2);
       //getMonth gives you 0-11 so add 1
       document.release.month.value = curr_dt.getMonth() + 1;
       document.release.day.value = curr_dt.getDate();
       var hours = curr_dt.getHours();
       var minutes = curr_dt.getMinutes();

    The hours will take a little more work. Midnight comes up as 0; we will need to substitute this with 12 and tack on a "AM." If the number is above 12 we will need to subtract 12 from the number to start with 1 PM and go up to 11 PM, and if the number is 12 we need to also have a "PM" at the end but otherwise leave the number alone. Also, the minutes will not always be 2 digits. We will need to have a 01, 02, 03 type of format for them. All this means using a few "if" constructs.

    //if minutes are 1-9 we need a leading zero
       if(minutes < 10)
       {
          minutes = "0" + minutes;
       }
    //new day starts unless you are a programmer
       if(hours == 0)
       {
          document.release.time.value = 12 + ":" + minutes + " AM";
       }
    //the noon hour is here so tack on a PM
       else if(hours = 12)
       {
          document.release.time.value = hours + ":" + minutes + " PM";
       }
    //we are past noon. subtract 12 to start at 1 and go up.
       else if
       {
          document.release.time.value = (hours - 12) + ":" + minutes + " PM";
       }
       else
       {
          document.release.time.value = hours + ":" + minutes + " AM";
       }
    }


    That was a lot to go through, but now we have a properly formatted date and time. This sets the default value for the fields when the page loads. If the user wants to change it they can.


    More Web Hosting How-Tos Articles
    More By Chris Root

    WEB HOSTING HOW-TOS ARTICLES

    - Phishing Scams: An Overview and How to Detec...
    - Tips for Safe Downloading Online
    - How To Avoid Spam
    - How to Get Into Ethical Hacking
    - How to Prevent Drive-by Downloads
    - Facebook Timeline Tips and Tricks
    - How to Keep Up with Facebook`s Changes
    - Wi-Fi Network Security Tips
    - Tips for Safe Online Holiday Shopping
    - Facebook Privacy: Keeping Up with the Const...
    - Tips for Facebook Privacy
    - How to Cover Your Tracks on the Web
    - SSH Keys for FileZilla and Putty in Cpanel
    - How to Create a Filezilla FTP User
    - How to Install FileZilla Server

    Developer Shed Affiliates

     




    © 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap