[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

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

0
nmarano
Asked:
nmarano
  • 5
1 Solution
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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
 
nmaranoAuthor Commented:
I accepted my own solution because my issue resolved itself as I was trouble shooting the issue.

Thanks
Nick
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now