Date range picker for Web-based applications

This could be used as an independent page (embedded), or as a part of the form (page). In the second case drop <html>, <head> and <body> tags, insert script part of the code into the JS Header and the rest of the code into the form by marking as Pass-Thru HTML text.


<title>Fast Date Picker</title>
button {
		 border-left: 1px solid buttonhighlight;
		 border-right: 1px solid buttonshadow;
		 border-top: 1px solid buttonhighlight;
		 border-bottom: 1px solid buttonshadow;
 		 text-align: center;}
a      {color:#0000FF;
<script language="JavaScript1.2">

function doAction(el){
el.style.borderStyle = "inset";

var elStart = 0;
var elEnd = 0;
function doFlexSelection(el)
{var Year = document.forms[0].year.value;

 for(i=1; i<13; i++)
        {elStart = i;

 for(i=1; i<13; i++)
        {elEnd = i;


elStart = eval(elStart); 
elEnd = eval(elEnd);

if(elStart == elEnd && eval("document.forms[0].sb"+elStart).style.borderStyle == "outset")

for(i=elStart; i<=elEnd; i++)
   	 eval("document.forms[0].sb"+i).style.borderStyle ='inset';
 elStart = (elStart < 10 ? "0" + elStart : elStart);
 elEnd = (elEnd < 10 ? "0" + elEnd : elEnd);
 document.forms[0].StartDate.value=Year + "-"+ elStart +"-01"; 
 if(elEnd == "01" || elEnd == "03" || elEnd == "05" || elEnd == "07" || elEnd == "08" || elEnd == "10" || elEnd == "12")
  	document.forms[0].EndDate.value= Year + "-"+ elEnd +"-31"; 
 else if(elEnd == "02")
   document.forms[0].EndDate.value= Year + "-"+ elEnd +"-28";
   document.forms[0].EndDate.value= Year + "-"+ elEnd +"-30";

function doFlexSelectionReset(el)
 el.style.borderStyle ='outset';

 for(i=1; i<22; i++)
    {eval("document.forms[0].sb"+i).style.borderStyle ='outset';
 document.forms[0].StartDate.value = ''; 
 document.forms[0].EndDate.value = '';



<fieldset style="width:360; background:buttonface"><legend><b><font face="Arial" size="2">Fast
    Selection Date Picker</font></b></legend>
        <font face="Arial" size="2">Start Date:</font> <input type="text" name="StartDate" size="10" readonly style="color: #FF0000;>  <font size="2" face="Arial">End Date: 
  <input type="text" name="EndDate" size="10" readonly style="color: #FF0000;">
<hr align="left">
  <div align="center">
<table style="margine-left: 10px; color: #000080" border="0" width="129" height="1" cellspacing="0" cellpadding="0"> 
    <td colspan="4"><button id="sb1" style="height:20px; width:25px; font:menu" onClick="doFlexSelection(this);">Jan</button>
    <button id="sb2" style="height:20px; width:25px;" onClick="doFlexSelection(this);">Feb</button>
    <button id="sb3" style="height:20px; width:25px;" onClick="doFlexSelection(this);">Mar</button>
    <button id="sb4" style="height:20px; width:25px;" onClick="doFlexSelection(this);">Apr</button>
    <button id="sb5" style="height:20px; width:25px;" onClick="doFlexSelection(this);">May</button>
    <button id="sb6" style="height:20px; width:25px;" onClick="doFlexSelection(this);">Jun</button>
    <button id="sb7" style="height:20px; width:25px;" onClick="doFlexSelection(this);">Jul</button>
    <button id="sb8" style="height:20px; width:25px;" onClick="doFlexSelection(this);">Aug</button>
    <button id="sb9" style="height:20px; width:25px;" onClick="doFlexSelection(this);">Sep</button>
    <button id="sb10" style="height:20px; width:25px;" onClick="doFlexSelection(this);">Oct</button>
    <button id="sb11" style="height:20px; width:25px;" onClick="doFlexSelection(this);">Nov</button>
    <button id="sb12" style="height:20px; width:25px;" onClick="doFlexSelection(this);">Dec</button></td>
    <select size="1" name="year" style="font: menu; padding: 0" onChange="doFlexSelectionReset(); StartDate.value=''; EndDate.value=''">
      <option value="2002">2002</option>
      <option value="2001" selected>2001</option>
      <option value="2000">2000</option>
    <td colspan="4">
      <button id="sb13" style="height:20px; width:73px;" onClick="doFlexSelectionReset(this); sb1.click(); sb3.click();">1 Quart</button>
      <button id="sb14" style="height:20px; width:4px;" onClick="doFlexSelectionReset(this); sb1.click(); sb6.click();"></button>
      <button id="sb15" style="height:20px; width:71px;" onClick="doFlexSelectionReset(this); sb4.click(); sb6.click();">2 Quart</button>
      <button id="sb16" style="height:20px; width:4px;" onClick="doFlexSelectionReset(this); sb4.click(); sb9.click();"></button>
      <button id="sb17" style="height:20px; width:71px;" onClick="doFlexSelectionReset(this); sb7.click(); sb9.click();">3 Quart</button>
      <button id="sb18" style="height:20px; width:4px;" onClick="doFlexSelectionReset(this); sb7.click(); sb12.click();"></button>
      <button id="sb19" style="height:20px; width:73px;" onClick="doFlexSelectionReset(this); sb10.click(); sb12.click();">4 Quart</button>
    <td rowspan="2"><button id="sb20" title="Date Reset" style="height:40px; width:50px;" onClick="doFlexSelectionReset(this);">Reset</button></td>
    <td colspan="4">
    <button id="sb21" style="height:20px; width:300px;" onClick="doFlexSelectionReset(this); sb1.click(); sb12.click();">Year</button>


This was first published in October 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.