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

//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>

Open in new window

LVL 2
nmaranoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

micropc1Commented:
From the examples on mattkruse.com that looks to be correct... see here:

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.
0
jjperezaguinagaCommented:
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
0
nmaranoAuthor Commented:
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...

   
<cfloop list="#disableDays#" index="i">
    <cfoutput>
    	#i#<br />
    </cfoutput>
</cfloop><cfabort>

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

nmaranoAuthor Commented:
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?

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

Open in new window

0
nmaranoAuthor Commented:
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>	

Open in new window

0
nmaranoAuthor Commented:
Experts-

Not sure exactly what I changed that finally fixed the issue.  One thing that I did notice were the single quotes within the javascript for the value ('0,6').  Once I removed the quotes, the calendar seems to work as expected...  

cal.setDisabledWeekDays(0,6);

Thanks for your suggestions
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nmaranoAuthor Commented:
I accepted my own solution because my issue resolved itself as I was trouble shooting the issue.

Thanks
Nick
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.