Solved

Function assistance

Posted on 2012-03-19
7
253 Views
Last Modified: 2012-03-25
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
Comment
Question by:nmarano
  • 5
7 Comments
 
LVL 7

Expert Comment

by:micropc1
ID: 37739288
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
 
LVL 6

Expert Comment

by:jjperezaguinaga
ID: 37739706
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
 
LVL 2

Author Comment

by:nmarano
ID: 37741542
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Author Comment

by:nmarano
ID: 37741670
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
 
LVL 2

Author Comment

by:nmarano
ID: 37741706
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
 
LVL 2

Accepted Solution

by:
nmarano earned 0 total points
ID: 37741763
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
 
LVL 2

Author Closing Comment

by:nmarano
ID: 37762349
I accepted my own solution because my issue resolved itself as I was trouble shooting the issue.

Thanks
Nick
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now