Forum Moderators: open
Basically what I'm trying to do is use that script to allow a user to enter a date into a textbox using a javascript calender.
The script works just fine however i cant get it to work with my function which takes today's date and subtracts it from the chosen date to give us the difference between the two dates in days.
For example if I entered 10/26/2009 it would set another textbox's value (in this case "days") to be 1.
The entire thing is supposed to happen as soon as any change is made however it wont work if the date is changed using the above method. It works just fine if I manually enter a date though. My code is below.
Thanks for any help!
<html>
<head>
<script type="text/javascript" src="js/mootools-1.2.3-core.js"></script>
<script type="text/javascript" src="js/mootools-1.2.3.1-more.js"></script>
<script type="text/javascript" src="js/calendar-eightysix-v1.0.js"></script>
<link type="text/css" media="screen" href="css/calendar-eightysix-default.css" rel="stylesheet" />
<script type='text/javascript'>
function getDays(co)
{
today = new Date()
var days= document.getElementById('days');
var arco = co.split("/");
var codate = new Date(arco[2], arco[0]-1, arco[1]);
var one = 1000*60*60*24;
days.value = Math.ceil((codate.getTime()-today.getTime())/(one));
}window.addEvent('domready', function() {
new CalendarEightysix('checkout', { 'theme': 'default blue', 'minDate': 'today' });
});
</script>
</head>
<body>
Date: <input name="checkout" id="checkout" value="" size="11" onChange="getDays(this.value)"><br />
Days Difference: <input name="days" id="days" value="" size="2" />
</body>
</html>
On a side note, Mootools already has predefined functions, like to find the difference between days. You might want to look into that (link below) which will save you a lot of time.
[mootools.net...]