Solved

Function assistance

Posted on 2012-03-19
7
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

735 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