Style Sheets
  Home arrow Style Sheets arrow Page 3 - Creating a Simple Date Picker with JavaScr...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Creating a Simple Date Picker with JavaScript and CSS
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 18
    2007-02-21

    Table of Contents:
  • Creating a Simple Date Picker with JavaScript and CSS
  • An Example Form
  • The Calendar Popup
  • The CSS

  • 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
     
     
    ADVERTISEMENT


    Creating a Simple Date Picker with JavaScript and CSS - The Calendar Popup


    (Page 3 of 4 )

    Next we have to code the calendar popup which allows your visitors to select the required date. To do this, we can just create a floating div that sits above the page but remains unseen until the user hits the calendar icon. In the HTML file, begin the following div:

    <div class="picker">
      <select class="month">
       
    <option>Month</option>
       
    <option>January</option>
       
    <option>February</option>
       
    <option>March</option>
       
    <option>April</option>
       
    <option>May</option>
       
    <option>June</option>
       
    <option>July</option>
        
    <option>August</option>
       
    <option>September</option>
       
    <option>October</option>
       
    <option>November</option>
       
    <option>December</option>
     
    </select>

      <select class="year">
       
    <option>Year</option>
       
    <option>2000</option>
       
    <option>2001</option>
       
    <option>2002</option>
       
    <option>2003</option>
       
    <option>2004</option>
       
    <option>2005</option>
       
    <option>2006</option>
       
    <option>2007</option>
       
    <option>2008</option>
       
    <option>2009</option>
     
    </select>

    All we've done so far is opened the container div and added two select box elements containing months and years. I've added the class attributes required for the CSS to work in this section so that we don't have to keep going back to the HTML file.

    The scope of the years select box is going to differ depending on the date you are asking your visitors to enter. A date of birth request, for example, is going to have a far greater range of dates than a delivery date choice. In this example I've used a simple range to illustrate the functionality.

    Select elements, while difficult and inconsistently styled across browsers, seem the best choice here in terms of minimizing and simplifying the code required. Another way we could do it would be to use a normal text input field, with a graphic representing a button placed directly at its right-hand edge, and an invisible div below it containing multiple paragraph elements that hold the choices. When the graphic button is selected, the div, aligned directly with the bottom of the text field, becomes visible. When one of the p elements is selected, DOM scripting methods could be used to copy its contents to the text field. It could be done in this way, but this is outside of the scope of this article and would result in a great deal more code. Now let's move on to the days part of the date-picker:

      <a href="" class="datelive">1</a><a href=""
    class="datelive">2</a><a href="" class="datelive">3</a><a href=""
    class="datelive">4</a><a href="" class="datelive">5</a><a href=""
    class="datelive">6</a>
      <a href="" class="datelive">7</a><a href=""
    class="datelive">8</a><a href="" class="datelive">9</a><a href=""
    class="datelive">10</a><a href="" class="datelive">11</a><a
    href="" class="datelive">12</a>
      <a href="" class="datelive">13</a><a href=""
    class="datelive">14</a><a href="" class="datelive">15</a><a
    href="" class="datelive">16</a><a href="" class="datelive">17</a><a href="" class="datelive">18</a>
      <a href="" class="datelive">19</a><a href=""
    class="datelive">20</a><a href="" class="datelive">21</a><a
    href="" class="datelive">22</a><a href="" class="datelive">23</a><a href="" class="datelive">24</a>
     
    <a href="" class="datelive">25</a><a href=""
    class="datelive">26</a><a href="" class="datelive">27</a><a href="" class="datelive">28</a><a href=""
    class="datelive">29</a><a href="" class="datelive">30</a>
     
    <a href="" class="datelive">31</a><a href=""
    class="dateunlive"></a><a href="" class="dateunlive"></a><a
    href="" class="dateunlive"></a><a href="" class="dateunlive"></a>

    </div>

    The days part is simply a long list of link elements which will be styled to represent squares, with each square corresponding to a different day. We also close the div off because as far as the HTML is concerned, that is all we need. I agree that it's not pretty to look at (either code-wise or on the page), but when we come to the CSS for it, everything can be straightened out.

    More Style Sheets Articles
    More By Dan Wellman


       · Hi Everyone, thanks for reading. The date picker is a useful addition to anyone...
       · The .picker style specifies display:none...so if you wonder why your calendar...
       · The display style is dynamically changed with JavaScript in the next article, which...
       · hey dear when will be the next part published
       · Hi, the next part of the tutorial has been published, it can be found at...
     

    STYLE SHEETS ARTICLES

    - Creating Three-Column Web Page Layous with N...
    - Swapping Column Positions in Web Page Layout...
    - Creating Web Page Layouts with Negative Marg...
    - Creating Gradients for Individual Containers...
    - Creating Gradients for Web Page Headers with...
    - SEO Scrolling Frames Problem Solved
    - Building Cross-Browser Background Effects wi...
    - CSS: Pseudo
    - Using PNG Images to Build Background Effects
    - CSS: Continuing the Clarification of CSS Cla...
    - CSS: Top Secret Classification
    - CSS: Dimensions
    - CSS: Margins and Padding
    - CSS: Crossing the Border
    - CSS: Text, Fonts, and Tables







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway