Access the answers to your technology questions today.
Subscribe Now
30-day free trial. Register in 60 seconds.
What Makes Experts Exchange Unique?
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.
Try it out and discover for yourself.
Subscribe Now
30-day free trial. Register in 60 seconds.
Join the Community
Give a Little. Get a Lot.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Join the Community
by: mplungjanPosted on 2006-05-26 at 02:03:23ID: 16767515
How about not allowing them to enter an illegal date in the first place?
rm.year.se lectedInde x].value orm.month. selectedIn dex].value =29;// save the minimum days ++ m.day.opti ons.length -1] = new Option(i,i)
i<n;i++) { length-1] = new Option(i,i) alue); >0)?diff:0 ;
Hours()+1;
m)"> m)">
<html>
<head>
<title>Untitled</title>
<script>
/* Set days in month script
Copyright (c) 2003-2006 Michel Plungjan "javascripts (a) planet.nl" */
// Change the values below if needed:
adjustYears=true; // fix the year drop down to be around now.
yearAdjustment=-2; // how many years prior to this year
numberOfYears = 5; // how many years in the dropdown
function setDate(theForm) {
var year = theForm.year.options[theFo
if (!year) return
var month = theForm.month.options[theF
if (!month) return
var d = new Date(year,month,0); // last day in the previous month because months start on 0
var daysInMonth = d.getDate();
theForm.day.options.length
if (daysInMonth>28) for (i=29;i<=daysInMonth;i++) {
theForm.day.options.length
theForm.day.options[theFor
}
}
function setNow() {
var now = new Date()
var ySel = document.forms[0].year;
var mSel = document.forms[0].month;
var dSel = document.forms[0].day;
var hSel = document.forms[0].hour;
var minSel = document.forms[0].min;
var year = now.getFullYear();
if (adjustYears) {
var firstYear = year + yearAdjustment;
ySel.options.length=1; // remove all but 1st option
for (var i=firstYear, n=firstYear+numberOfYears;
ySel.options.length++
ySel.options[ySel.options.
}
}
var minYear = parseInt(ySel.options[1].v
var diff = year-minYear+1;
ySel.selectedIndex=((diff)
mSel.selectedIndex = now.getMonth()+1;
dSel.selectedIndex = now.getDate(); // NB: Not 0 based
hSel.selectedIndex=now.get
minSel.selectedIndex= now.getMinutes()+1;
}
</script>
</head>
<body onLoad="setNow()">
<form>
<select name="year" onChange="setDate(this.for
<option value="">Year
<option value="2003">2003
<option value="2004">2004
<option value="2005">2005
<option value="2006">2006
<option value="2007">2007
</select>
<select name="month" onChange="setDate(this.for
<option value="">Month
<option value="1">Jan
<option value="2">Feb
<option value="3">Mar
<option value="4">April
<option value="5">May
<option value="6">June
<option value="7">July
<option value="8">Aug
<option value="9">Sep
<option value="10">Oct
<option value="11">Nov
<option value="12">Dec
</select>
<select name="day"><!-- Use all days to help NS4 -->
<option value="">Day
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
<option value="16">16
<option value="17">17
<option value="18">18
<option value="19">19
<option value="20">20
<option value="21">21
<option value="22">22
<option value="23">23
<option value="24">24
<option value="25">25
<option value="26">26
<option value="27">27
<option value="28">28
<option value="29">29
<option value="30">30
<option value="31">31
</select>
<select name="hour">
<option value="">Hour
<option value="0">00
<option value="1">01
<option value="2">02
<option value="3">03
<option value="4">04
<option value="5">05
<option value="6">06
<option value="7">07
<option value="8">08
<option value="9">09
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
<option value="16">16
<option value="17">17
<option value="18">18
<option value="19">19
<option value="20">20
<option value="21">21
<option value="22">22
<option value="23">23
</select>:
<select name="min">
<option value="">min
<option value="0">00
<option value="1">01
<option value="2">02
<option value="3">03
<option value="4">04
<option value="5">05
<option value="6">06
<option value="7">07
<option value="8">08
<option value="9">09
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
<option value="16">16
<option value="17">17
<option value="18">18
<option value="19">19
<option value="20">20
<option value="21">21
<option value="22">22
<option value="23">23
<option value="24">24
<option value="25">25
<option value="26">26
<option value="27">27
<option value="28">28
<option value="29">29
<option value="30">30
<option value="31">31
<option value="32">32
<option value="33">33
<option value="34">34
<option value="35">35
<option value="36">36
<option value="37">37
<option value="38">38
<option value="39">39
<option value="40">40
<option value="41">41
<option value="42">42
<option value="43">43
<option value="44">44
<option value="45">45
<option value="46">46
<option value="47">47
<option value="48">48
<option value="49">49
<option value="50">50
<option value="51">51
<option value="52">52
<option value="53">53
<option value="54">54
<option value="55">55
<option value="56">56
<option value="57">57
<option value="58">58
<option value="59">59
</select>
</form>
</body>
</html>