Forum Moderators: open

Message Too Old, No Replies

onChange not working properly.

         

trigoon

10:54 pm on Oct 25, 2009 (gmt 0)

10+ Year Member



Im having a problem using the script here [dev.base86.com...]

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>

Zipper

11:49 pm on Oct 25, 2009 (gmt 0)

10+ Year Member



Did you test this on multiple browsers? It could be related to the fact that there's no focus/blur on the textbox. Nevertheless, you can use the pickFunction option (check the link in your post, under Options) to bind the getDays() function when a date is picked.

trigoon

12:23 am on Oct 26, 2009 (gmt 0)

10+ Year Member



Oh I see thanks for that, I didnt realize the script had that, now I'm a bit confused on how to exactly use that feature. Although I know I should ask the script maker do you by chance have any idea on how I can actually use it? The documentation isn't very clear.

Thanks again!

trigoon

1:19 am on Oct 26, 2009 (gmt 0)

10+ Year Member



I got it working :) Thanks for all the help.

Zipper

1:26 am on Oct 26, 2009 (gmt 0)

10+ Year Member



Nice!

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