SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Java Help

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

    Java Help

    I have the following js code that displays a popup calander and when you click on a date the date goes into a form field. What I want to change is the current day on the calendar the background of the <td> is yellow. Suggestions??

    <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, "mm")#
    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="javascriptpener.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="javascriptpenCalWin_#attributes.target#()"><img src="#attributes.image#" border=0></a>
    <cfelse>
    <a href="javascriptpenCalWin_#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>

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Birmingham, UK
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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="javascriptpener.placeDate_#attributes.target#(' + theDate.getMonth() + ',' + currDay + ',' + theDate.getFullYear() + ')">' + currDay++ + '</a></td>')
    if (currDay > totalDays[theDate.getMonth()])
    printDays = false
    }

    in this part of the code, you need to find the part where the value of x is equal to the current date.

    soooo it should be something like this

    [code]
    var day = theDate.getDate()
    for (x=1; x<=rowsNeeded; x++){
    CalWin.document.write('<tr>')

    //this is the part where it loops throug the days

    for (y=0; y<=6; y++){
    if (currDay == 1 && !printDays && startDay == y)
    printDays = true

    //this is where it makes the colums to put the date in
    so you need another if statement to see if y = the date

    if(y==day){
    CalWin.document.write('<td align="center" width=14.28% bgcolor="#FFFF00"')
    }
    else{
    CalWin.document.write('<td align="center" width=14.28%>')
    }
    if (printDays){
    CalWin.document.write('<a href="javascriptpener.placeDate_#attributes.target#(' + theDate.getMonth() + ',' + currDay + ',' + theDate.getFullYear() + ')">' + currDay++ + '</a></td>')
    if (currDay > totalDays[theDate.getMonth()])
    printDays = false
    }

    the main part of the code is this
    if(y==day){
    CalWin.document.write('<td align="center" width=14.28% bgcolor="#FFFF00"')
    }
    else{
    CalWin.document.write('<td align="center" width=14.28%>')
    }

    hope i helped...

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

    Having problems

    I have tried to put what you wrote and thank you for that. The following error is what I get.
    Line : 107
    Char: 1
    Error: Expected'}'
    Code: 0

    This is my modified code -

    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, "mm")#
    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>')
    var day = theDate.getDate()
    for (x=1; x<=rowsNeeded; x++){
    CalWin.document.write('<tr>')

    //this is the part where it loops throug the days

    for (y=0; y<=6; y++){
    if (currDay == 1 && !printDays && startDay == y)
    printDays = true

    //this is where it makes the colums to put the date in so you need another if statement to see if y = the date

    if(y==day){
    CalWin.document.write('<td align="center" width=14.28% bgcolor="##FFFF00"')
    }
    else{
    CalWin.document.write('<td align="center" width=14.28%>')
    }
    if (printDays){
    CalWin.document.write('<a href="javascriptpener.placeDate_#attributes.target#(' + theDate.getMonth() + ',' + currDay + ',' + theDate.getFullYear() + ')">' + currDay++ + '</a></td>')
    if (currDay > totalDays[theDate.getMonth()])
    printDays = false
    }


    if(y==day){
    CalWin.document.write('<td align="center" width=14.28% bgcolor="##FFFF00"')
    }
    else{
    CalWin.document.write('<td align="center" width=14.28%>')
    }


    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()
    }


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
  •