nmarano
asked on
Function assistance
Experts-
I am using this code below for a pop up calendar. the function accepts a variable returned from a query #disableDays# The script take the variable and creates strike throughs on the days that I am trying to disable. If the query returns two days, '0,6' the code doesn't run. If it retunns one day '6' the calendar works properly. Can someone tell me how I can modify this code in order to accept multiple days? Any help would be appreciated...
I am using this code below for a pop up calendar. the function accepts a variable returned from a query #disableDays# The script take the variable and creates strike throughs on the days that I am trying to disable. If the query returns two days, '0,6' the code doesn't run. If it retunns one day '6' the calendar works properly. Can someone tell me how I can modify this code in order to accept multiple days? Any help would be appreciated...
//This is the function that is on an include file
// Set which weekdays should not be clickable
function CP_setDisabledWeekDays() {
this.disabledWeekDays = new Object();
for (var i=0; i<arguments.length; i++) { this.disabledWeekDays[arguments[i]] = true; }
}
//This is the script that is on my form page which loads the calendar...
<script language="JavaScript" ID="js1">
var cal = new CalendarPopup();
// block off days where the dealer doesn't schedule appts.
cal.setDisabledWeekDays(#disableDays#);
cal.addDisabledDates(null, '#DateFormat(lastAvailableDate,'mm/dd/yy')#');
cal.setReturnFunction('setValidTimes');
// block off holidays
<cfloop query="getHoliday">
cal.addDisabledDates('#DateFormat(holiday,'mm/dd/yy')#');
cal.addDisabledDates('#DateFormat(DateAdd('d',1,holiday),'mm/dd/yy')#');
</cfloop>
cal.addDisabledDates('#DateFormat(disableDay,'mm/dd/yy')#');
function showRollover(id){
document.getElementById(id).style.visibility = "visible";
}
function hideRollover(id){
document.getElementById(id).style.visibility = "hidden";
}
function setValidTimes(y,m,d) {
if (window.CP_targetInput!=null) {
var dt = new Date(y,m-1,d,0,0,0);
if (window.CP_calendarObject!=null) { window.CP_calendarObject.copyMonthNamesToWindow(); }
window.CP_targetInput.value = formatDate(dt,window.CP_dateFormat);
} else {
alert('Error');
}
updateTimeRange(y,m,d,#session.AgentScript.prospect.clientid#);
}
</script>
Greetings nmarano,
If your code is throwing a problem with multiple queries, then validate what you are receiving without modifying your code.
For instance, use the .length property to see if you get more than one value. If you know how your data is behaving, you should be able to iterate through it to get the right value. Also, never trust data, so a validation in your process is always good.
If the query retrieves a string instead of an array, split it with a regex (/,/gi); if it's an object then use (for var key in object) if (object.hasOwnProperty(key ))... don't break your head over a problem that has a different nature than the code itself you are pasting.
Hope it helped,
-JJ
If your code is throwing a problem with multiple queries, then validate what you are receiving without modifying your code.
For instance, use the .length property to see if you get more than one value. If you know how your data is behaving, you should be able to iterate through it to get the right value. Also, never trust data, so a validation in your process is always good.
If the query retrieves a string instead of an array, split it with a regex (/,/gi); if it's an object then use (for var key in object) if (object.hasOwnProperty(key
Hope it helped,
-JJ
ASKER
Experts-
The values are in a valuelist when returned from the CF query. I just wrote this quick loop to see if they would output correctly, and they do...
The values are in a valuelist when returned from the CF query. I just wrote this quick loop to see if they would output correctly, and they do...
<cfloop list="#disableDays#" index="i">
<cfoutput>
#i#<br />
</cfoutput>
</cfloop><cfabort>
ASKER
When I run the code and view the source, I do see the 0,6 in the script for disabled days....
Do you guys see anything that prevents it from working properly?
Do you guys see anything that prevents it from working properly?
<script language="JavaScript" ID="js1">
var cal = new CalendarPopup();
// block off days where the dealer doesn't schedule appts.
cal.setDisabledWeekDays('0,6');
cal.addDisabledDates(null, '03/21/12');
cal.setReturnFunction('setValidTimes');
// block off holidays
cal.addDisabledDates('03/20/12');
function showRollover(id){
document.getElementById(id).style.visibility = "visible";
}
function hideRollover(id){
document.getElementById(id).style.visibility = "hidden";
}
function setValidTimes(y,m,d) {
if (window.CP_targetInput!=null) {
var dt = new Date(y,m-1,d,0,0,0);
if (window.CP_calendarObject!=null) { window.CP_calendarObject.copyMonthNamesToWindow(); }
window.CP_targetInput.value = formatDate(dt,window.CP_dateFormat);
} else {
alert('Error');
}
updateTimeRange(y,m,d,'39','http://test.keywordadvisors.com/nickdev/');
}
</script>
ASKER
This is the input tag.....
<input name="ApptDate" value="select date" size="8" maxlength="11" type="text" onClick="cal.select(document.form1.ApptDate,'anchordate','MM/dd/yyyy','#DateFormat(calStartDate,'mm/dd/yyyy')#'); return false;" />
<a href="##" onClick="cal.select(document.form1.ApptDate,'anchordate','MM/dd/yyyy','#DateFormat(calStartDate,'mm/dd/yyyy')#'); return false;"
TITLE="Please select your date" NAME="anchordate" ID="anchordate"><img src="<cfoutput>#application.baseURL#</cfoutput>images/calendar.gif" border="0" style="display: inline;"></a>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I accepted my own solution because my issue resolved itself as I was trouble shooting the issue.
Thanks
Nick
Thanks
Nick
http://www.mattkruse.com/javascript/calendarpopup/source.html
Have you tried manually typing in multiple values to see if it will work? Maybe there is a problem with the ColdFusion output. If 'disabledays' is a column in a cfquery that contains more than 1 row you'll need to use #valuelist(disabledays)# to convert it to a list.