Home arrow Style Sheets arrow Page 2 - Creating a Simple Date Picker with JavaScript and CSS
STYLE SHEETS

Creating a Simple Date Picker with JavaScript and CSS


Getting visitors to fill out certain parts of forms can be tricky, especially when the item you want them to fill out can be rendered in many different formats. Consider how many different ways one can write a date, for instance. In this first part of a two-part article, you will learn how to build a date picker that minimizes this headache.

Author Info:
By: Dan Wellman
Rating: 4 stars4 stars4 stars4 stars4 stars / 58
February 21, 2007
TABLE OF CONTENTS:
  1. · Creating a Simple Date Picker with JavaScript and CSS
  2. · An Example Form
  3. · The Calendar Popup
  4. · The CSS

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Creating a Simple Date Picker with JavaScript and CSS - An Example Form
(Page 2 of 4 )

Initially, you'll need an example form, with some date fields on it. I won't waste time by using an elaborate form, so we'll just have a couple of example fields on it that will serve to illustrate the date picker. Something like the following should suffice:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
http://www.w3.org/TR/html4/strict.dtd>
<html lang="en">
 
<head>
   
<title>Date Picker Example</title>
 
<head>
 
<body>
   
<h1>A Generic Form</h1>
   
<div>
     
<form action="">
       
<span> Enter A Date:</span><input type="text"><img
src="calendar.gif" alt="Datepicker">
     
</form>
   
</div>
 
</body>
</html>

We begin with the DOCTYPE, naturally, then a basic page with a basic form on it. The lang attribute of the HTML element is included for validity. Save this as datepicker.html or something similar. Now we can add some CSS to make the page look a little more appealing and line things up better. Add the following selectors and rules to a new page in your text editor:

h1 {
 
font-family:arial, sans-serif;
 
color:#003399;
 
border-bottom-width:3px;
 
border-bottom-color:#ffcc00;
 
border-bottom-style:solid;
}

img {
 
position:relative;
 
top:10px;
 
padding-left:10px;
}

.text {
 
font-family:arial, sans-serif;
 
color:#003399;
 
padding-right:10px;
}

.textbox {
 
border-width:1px;
 
border-color:#ffcc00;
 
border-style:solid;
}

You'll also need to go back to the HTML and add the code shown in bold below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
http://www.w3.org/TR/html4/strict.dtd>
<html lang="en">
 
<head>
   
<title>Date Picker Example</title>
   
<link rel="stylesheet" type="text/css"
herf="datepicker.css">
 
<head>
 
<body>
   
<h1>A Generic Form</h1>
    
<div>
     
<form action="">
       
<span class="text">Enter A Date:</span><input
class="textbox" type="text"><img src="calendar.gif"
alt="Datepicker">
     
</form>
    
</div>
  
</body>
</html>

So now it should look adequate for this example.


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials