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.
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: