SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2000
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pop Up calendar Help

    I found this code for a popup calendar that works great. The only thing that I need help with is that the way that it formats that date into my text box is not what I need. Currently its format is 6/6/2001. What I need is 06/06/2001.
    Anyone have suggestions.

    This code was found in allaire.com dev section the code is part of CF_CAL.

    Code:
    <cftry>
    
    <cfif parameterexists(attributes.target) EQ 0>
    <cfthrow message="NoTarget">
    <cfelseif parameterexists(attributes.formname) EQ 0>
    <cfthrow message="NoTarget">
    </cfif>
    
    
    <cfparam name="attributes.date" default="#Now()#">
    <cfparam name="attributes.image" default="0">
    
    <cfoutput>
    <script language="JavaScript">
    
    var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December")
    var totalDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31)
    
    
    function openCalWin_#attributes.target#() { 
    	stats='toolbar=no,location=no,directories=no,status=no,menubar=no,'
    	stats += 'scrollbars=no,resizable=no,width=300,height=250'
    	CalWin = window.open ("","Calendar",stats)
    	
    	
    	var calMonth = #DateFormat(attributes.date, "M")#
    	var calYear = #DateFormat(attributes.date, "YYYY")#
    	
    	
    	theDate = new Date(calYear, (calMonth - 1), 1)
    
    	buildCal_#attributes.target#(theDate)
    	
    }
    
    function buildCal_#attributes.target#(theDate) {
    	
    	var startDay = theDate.getDay()
    	var printDays = false
    	var currDay = 1
    	var rowsNeeded = 5
    	
    	if (startDay + totalDays[theDate.getMonth()] > 35)
    		rowsNeeded++
    	
    	CalWin.document.write('<html><head><Title>Select a Date</title>')
    	CalWin.document.write('<STYLE TYPE="text/css">')
    	CalWin.document.write('A { color: ##000000; font-family:Arial,Helvetica;font-size:14pt; font-weight: bold; text-decoration: none}')
    	CalWin.document.write('A:hover { color: red; }')
    	CalWin.document.write('</STYLE></head>')
    	CalWin.document.write('<body><a name="this"></a>')
    	CalWin.document.write('<table align=center height=100% width=100% border=2 bordercolor=Black cellpadding=0 cellspacing=0>')
    	CalWin.document.write('<tr><th bgcolor=Blue colspan=7><font face=Arial color=white>' + months[theDate.getMonth()] + ' ' + theDate.getFullYear() + '</font></th></tr>')
    	CalWin.document.write('<tr bgcolor="##0000ff"><th><font face=Arial color=white>Su</font></th><th><font face=Arial color=white>Mo</font></th><th><font face=Arial color=white>Tu</font></th><th><font face=Arial color=white>We</font></th><th><font face=Arial color=white>Th</font></th><th><font face=Arial color=white>Fr</font></th><th><font face=Arial color=white>Sa</font></th></tr>')
    	for (x=1; x<=rowsNeeded; x++){
    		CalWin.document.write('<tr>')
    		for (y=0; y<=6; y++){
    			if (currDay == 1 && !printDays && startDay == y)
    				printDays = true
    			CalWin.document.write('<td align="center" width=14.28%>')
    			if (printDays){
            		CalWin.document.write('<a href="javascript:opener.placeDate_#attributes.target#(' + theDate.getMonth() + ',' +  currDay + ',' + theDate.getFullYear() + ')">' + currDay++ + '</a></td>')
    				if (currDay > totalDays[theDate.getMonth()])
    					printDays = false
    			}
    			else
    				CalWin.document.write('&nbsp;</td>')
    		}		
    		CalWin.document.write('</tr>')
    	}	
    	CalWin.document.write('<form><tr bgcolor="##0000ff"><td colspan=7 align="center"><input type="Button" size="2" name="Back" value="<<" onClick="opener.getNewCal_#attributes.target#(-1)"><font face=Arial color=white size="1"> Use the arrows to browse through the months.</font> <input type="Button" size="2" name="Forward" value=">>" onClick="opener.getNewCal_#attributes.target#(1)"></td></tr></form>')
    	CalWin.document.write('</table></body></html>')
    	CalWin.document.close()
    	
    }
    
    function getNewCal_#attributes.target#(newDir) {
    	if (newDir == -1){
    		theDate.setMonth(theDate.getMonth() - 1)
    		if (theDate.getMonth() == 0){
    			theDate.setMonth(12)
    			theDate.setYear(theDate.getYear() - 1)
    		}
    	}
    	else if (newDir == 1){
    		theDate.setMonth(theDate.getMonth() + 1)
    		if (theDate.getMonth() == 13){
    			theDate.setMonth(1)
    			theDate.setYear(theDate.getYear() + 1)
    		}
    	}
    		
    		
    	CalWin.document.clear();
    	buildCal_#attributes.target#(theDate);
    
    }
    
    function placeDate_#attributes.target#(monthNum, dayNum, yearNum){
    	var dateString = (monthNum + 1) + '/' + dayNum + '/' + yearNum
    
    	document.#attributes.formname#.#attributes.target#.value = dateString
    		 
    	CalWin.close()
    }
    
    </script>
     
    <cfif #attributes.image# NEQ 0>
    <a href="javascript:openCalWin_#attributes.target#()"><img src="#attributes.image#" border=0></a>
    <cfelse>
    <a href="javascript:openCalWin_#attributes.target#()">[C]</a>
    </cfif> 
    </cfoutput>
    
    <cfcatch type="Any">
    <script language="JavaScript">
    alert("You must supply a value for the FORMNAME & TARGET attributes!")
    </script>
    </cfcatch>
    </cftry>
    <Advisor Edit: [code tags used. >
    Last edited by mmj; Jun 16, 2001 at 10:45.

  2. #2
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Sorry eparker, but is this a problem with the javascript of coldfusion part of your code? Which needs fixing?

    Thanks, mmj
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2001
    Location
    Los Angeles
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    find this line and change it form
    var calMonth = #DateFormat(attributes.date, "M")#
    To
    var calMonth = #DateFormat(attributes.date, "MM")#

    If that works email me cause it was just luck. If it doesn't work, well sorry and good luck.
    bsacks
    http://www.middlepeak.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •