JavaScript
  Home arrow JavaScript arrow Page 4 - Completing a Simple Date Picker with JavaS...
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  
Mobile Linux 
App Generation ROI 
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? 
JAVASCRIPT

Completing a Simple Date Picker with JavaScript and CSS
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 8
    2007-03-14

    Table of Contents:
  • Completing a Simple Date Picker with JavaScript and CSS
  • Focusing on Visitor Selections
  • Adding the datestring
  • Finishing up

  • 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


    Completing a Simple Date Picker with JavaScript and CSS - Finishing up


    (Page 4 of 4 )

    Just before we finish up, we can do one more thing to tidy up the functionality of the datepicker. There is currently no way to close the date picker without picking a date, so if it is opened accidentally after a date has already been picked, the visitor has to go through the process of selecting the date again. A little extra code in the showPicker() function can ensure that the datepicker can be switched off easily in this situation:

    function showPicker() {
      
    if (pickeropen == "no") {
        
    document.getElementById("picker").style.display = "block";
        
    pickeropen = "yes";
      
    } else {
        
    document.getElementById("picker").style.display = "none";
        
    pickeropen = "no";
      
    }
    }

    You'll need to add a global variable of var pickeropen = "no"; somewhere in the file. I usually find it best to add all of the global variables at the top of the file. That's it; you now have one fully fledged datepicker that saves typing for your visitors and makes form processing easier for you. You can also add pickeropen = "no"; to the end of the hidePicker() function as well.

    Don't forget that you'll still need to check all of the data that's being submitted in the form for security reasons, but this is something that you'd need to do anyway. I just want to make it clear that just because you know exactly which format your dates are being submitted in, doesn't mean you don't need to guard against malicious user input.

    Some fully fledged date picker applications allow the visitor to select the day of the week as well as the day, month and year aspects of the date. While this approach has obvious benefits in the corporate world, allowing members of staff at a company to select date ranges that they would like to book off work as vacation time by selecting Monday to Friday of a specific week or month instead of having to enter each date sequentially for example, it does create a lot more coding. When this information is not required, the extra code and complexity can be done away with; the date picker shown in this example is easy to code and compact while remaining usable and effective. It also works consistently across IE 6 and 7 and FireFox 1 and 2.0, so most if not all of your visitors should be able to use it without any problems.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hi everyone,Thanks for perservering, the date-picker described here does have...
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT