hey, thanks for the replies! sorry i haven't responded in a bit, been busy with classes and every thing... you know how it goes.:rolleyes:
so i've been working on this a bit and this is some code i've come up with (sorry if my javascript is poor):
// the default multiple dates selected,
// first time the calendar is displayed
var MA = [];
//function to catch multipule selected dates, and display them
function closed(cal) {
//get the form fields and assign them to variables
var fm = document.getElementById("date");
var sfm = document.getElementById("sdate");
var efm = document.getElementById("edate");
// reset initial content.
fm.value = "";
sfm.value = "";
efm.value = "";
// Reset the "MA", in case one triggers the calendar again.
// CAREFUL! You don't want to do "MA = [];". We need to modify
// the value of the current array, instead of creating a new one.
// Calendar.setup is called only once! :-) So be careful.
MA.length = 0;
// walk the calendar's multiple dates selection hash
for (var i in cal.multiple) {
var d = cal.multiple[i];
// sometimes the date is not actually selected,
// so let's check
if (d) {
// OK, selected. Fill an input field or something.
fm.value += d.print("%m/%e/%Y; ");
// and push it in the "MA", in case one triggers the calendar again.
MA[MA.length] = d;
}
}
//for now use the current input field for the date source
var temp = fm.value;
//now split into an array
var dates = split("; ", fm.value, -1);
var x, y, holder;
FirstDate = new Date();
SecondDate = new Date();
for(x = 0; x < dates.length; x++){
for(y = 0; y < (dates.length-1); y++){
array_first = split("/", dates[y]);
array_second = split("/", dates[y+1]);
FirstDate.setMonth(array_first[0]);
FirstDate.setDate(array_first[1]);
FirstDate.setYear(array_first[2]);
SecondDate.setMonth(array_second[0]);
SecondDate.setDate(array_second[1]);
SecondDate.setYear(array_second[2]);
//here you can modify the condition to work for ascending or descending
if (FirstDate > SecondDate){
holder = dates[y+1];
dates[y+1] = dates[y];
dates[y] = holder;
}
}
}
sfm.value = dates[0].print;
efm.value = dates[dates.length].print;
cal.hide();
return true;
};
the function closed() is used as a callback function that the date picker calendar uses when the onClose event is triggered. previously, the function ended with printing the selected dates into fm.value, seperated by a semicolon and a space.
i get an error using the mozilla error console: "split is not defined", where i initially split fm.value into var dates by string "; ". if i get this working then it should sort the dates given (the order the dates are clicked in the calendar determines the order the dates would appear in fm.value), and put the first and last dates into their corresponding fields. i haven't quite gotten to checking if they are consecutive yet. any help with this would be great. thanks much!