KidsLovePC Contact Us
  Home   PHP  Graphics ASP  JavaScript   J2EE  HTML  JAVA   Swing   Webtip  Forums  Lyric  Free sheet music  Ringtones

Best books about Javasript

JavaScript Calendar Pull Down Menu

javascript, javascript detect chinese input formSee the following Javascript Calendar Pull Down Menu:

This script automatically fill the days of selected month, year.

javascript, javascript detect chinese input formHow to do it?

You need the following Javascript to build the above pull down menu calendar.

<script type="text/javascript">
function DateSelector(selYear, selMonth, selDay)
{
this.selYear = selYear;
this.selMonth = selMonth;
this.selDay = selDay;
this.selYear.Group = this;
this.selMonth.Group = this;
// add onchange event to year,month
if(window.document.all != null) // IE
{
this.selYear.attachEvent("onchange", DateSelector.Onchange);
this.selMonth.attachEvent("onchange", DateSelector.Onchange);
}
else // Firefox
{
this.selYear.addEventListener("change", DateSelector.Onchange, false);
this.selMonth.addEventListener("change", DateSelector.Onchange, false);
}

if(arguments.length == 4) // if no of argument is 4, the last one is Date format
this.InitSelector(arguments[3].getFullYear(), arguments[3].getMonth() + 1, arguments[3].getDate());
else if(arguments.length == 6) // if no of argument is 4, the last 3 should be year, month, date
this.InitSelector(arguments[3], arguments[4], arguments[5]);
else // take the default date
{
var dt = new Date();
this.InitSelector(dt.getFullYear(), dt.getMonth() + 1, dt.getDate());
}
}

// add minimum year
DateSelector.prototype.MinYear = 1900;

// add maximum year
DateSelector.prototype.MaxYear = (new Date()).getFullYear()+1;

// initialize year
DateSelector.prototype.InitYearSelect = function()
{

for(var i = this.MaxYear; i >= this.MinYear; i--)
{
//create option
var op = window.document.createElement("OPTION");

// set option value
op.value = i;

// set option content
op.innerHTML = i;


this.selYear.appendChild(op);
}
}

// initialize month
DateSelector.prototype.InitMonthSelect = function()
{
for(var i = 1; i < 13; i++)
{
var op = window.document.createElement("OPTION");
op.value = i;
op.innerHTML = i;
this.selMonth.appendChild(op);
}
}

// get days in a month
DateSelector.DaysInMonth = function(year, month)
{
var date = new Date(year, month, 0);
return date.getDate();
}

// initialize date
DateSelector.prototype.InitDaySelect = function()
{
var year = parseInt(this.selYear.value);
var month = parseInt(this.selMonth.value);
var daysInMonth = DateSelector.DaysInMonth(year, month);
this.selDay.options.length = 0;
for(var i = 1; i <= daysInMonth ; i++)
{
var op = window.document.createElement("OPTION");
op.value = i;
op.innerHTML = i;
this.selDay.appendChild(op);
}
}

DateSelector.Onchange = function(e)
{
var selector = window.document.all != null ? e.srcElement : e.target;
selector.Group.InitDaySelect();
}

DateSelector.prototype.InitSelector = function(year, month, day)
{
this.selYear.options.length = 0;
this.selMonth.options.length = 0;

this.InitYearSelect();
this.InitMonthSelect();
this.selYear.selectedIndex = this.MaxYear - year;
this.selMonth.selectedIndex = month - 1;

this.InitDaySelect();

this.selDay.selectedIndex = day - 1;
}
</script>

 

Then add the following code to where you want the pull down menu to be:

<select id="selYear"></select>
<select id="selMonth"></select>
<select id="selDay"></select>
<script type="text/javascript">
var selYear = window.document.getElementById("selYear");
var selMonth = window.document.getElementById("selMonth");
var selDay = window.document.getElementById("selDay");

//
new DateSelector(selYear, selMonth ,selDay, 2006, 1, 1);
//You may try this
// var dt = new Date(2004, 1, 29);
// new DateSelector(selYear, selMonth ,selDay, dt);
</script>

 

 

 

 

Best books about ASP & ASP.Net from Amazon
JavaScript Bible, Fifth Edition (Paperback) JavaScript & DHTML Cookbook (Paperback) JavaScript: The Definitive Guide (Paperback) Beginning JavaScript Second Edition (Paperback) JavaScript: The Complete Reference, Second Edition (Paperback)

 

Printer Inkjet A Z lyricsLearn ChineseHome|PHP|Swing|HTML|JavaScript|ASP|JAVA|Forum|WebTip|Contact Us
Copyright © kidslovepc.com All rights reserved(new). Privacy|Copyright
designed by info@kidslovepc.com

Please help us cover the web site maintenance fee.
barcode scanner Thermal Printer credit card machine bar code printer