JavaScript
  Home arrow JavaScript arrow Page 3 - 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 - Adding the datestring


    (Page 3 of 4 )

    Finally, we need to put datestring into the text field in the form. This is really simple; all we need is the following line of code:

    document.getElementById("datebox").value = datestring;

    You'll need to add an ID attribute to the text field in the HTML file, but that's pretty much it. To finish things off, you can call a function that closes the datepicker once the text field has received the date string:

    hidePicker();

    Creating the function that closes the calendar div is just as easy as it was to create the function that shows it, all that needs to be changed is the style to impose:

    function hidePicker() {
      
    document.getElementById("picker").style.display = "none";
    }

    You might want to add some additional styling to the text field holding the date string at this point; maybe shortening it and centering the text within it. You could also add some default text to the text field in the form by adding a value attribute of "DD/MM/YYYY." Also, after writing all of the code for the datepicker, we don't really want visitors just typing their date into the text field. To prevent the visitor from up updating the text box manually, you can add the disabled="disabled" attribute. One final attribute you can add to the text input is a title to tell the visitor to use the calendar icon. Something along the lines of; title="Click the calendar to open a datepicker" should suffice.

    More JavaScript Articles
    More By Dan Wellman


       · 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 1 hosted by Hostway
    Stay green...Green IT