Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Showing new Date() and future dates

    Hello,

    I'm stumped on this script that I'm trying to write. The goal is to show the current date and future dates while hiding the tables with older dates in the id. All I can get to show are the future dates. Any ideas? Any help will greatly be appreciated. Thank you.

    <script type="text/javascript">

    window.onload = init;
    var serverDate = "<!--#config timefmt="%m/%d/%Y"--><!--#echo var="DATE_LOCAL"

    function init() {
    hideOldDays();
    }//

    /* --------------------------------------------------------------------------------------

    -----------------------------------------------------------------------------------------*/

    function GetDay(intDay){
    var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday")
    return DayArray[intDay]
    }

    function GetMonth(intMonth){
    var MonthArray = new Array("January", "February", "March",
    "April", "May", "June",
    "July", "August", "September",
    "October", "November", "December")
    return MonthArray[intMonth]
    }

    function getDateStrWithDOW(){
    var today = new Date()
    var todayStr = GetDay(today.getDay()) + ", "
    todayStr += GetMonth(today.getMonth()) + " " + today.getDate()
    todayStr
    return todayStr
    }

    function hideOldDays() {

    var currentDate = new Date(serverDate);
    var tables = document.getElementsByTagName("TABLE");
    for (var i=0; i<tables.length; i++) {
    var t = tables[i];

    var dateStr =t.id.substr(5)
    var thisWeekDate = new Date(dateStr);
    if (currentDate > thisWeekDate) {
    document.getElementById(t.id).style.display = "none";
    }
    }
    }//

    </script>

    </HEAD>
    <BODY>
    <h3>Today is <SCRIPT Language="JavaScript">
    <!-- hide from old browsers
    document.write(getDateStrWithDOW())
    //--></h3>
    </SCRIPT>
    <br><br>
    <table id="date-05-31-2006" class="">
    <tr><th colspan="2">Wednesday 31</th></tr>
    <tr>
    <td>A</td>
    <td>B</td>
    </tr>
    </table>

    <table id="date-06-04-2006" class="">
    <tr><th colspan="2">June 4</th></tr>
    <tr>
    <td>A</td>
    <td>B</td>
    </tr>
    </table>


    <table id="date-06-05-2006" class="">
    <tr><th colspan="2">June 5</th></tr>
    <tr>
    <td>A</td>
    <td>B</td>
    </tr>
    </table>


    <table id="date-07-06-2006" class="">
    <tr><th colspan="2">June 6</th></tr>
    <tr>
    <td>A</td>
    <td>B</td>
    </tr>
    </table>

    <table id="date-12-07-2006" class="">
    <tr><th colspan="2">June 7</th></tr>
    <tr>
    <td>A</td>
    <td>B</td>
    </tr>
    </table>
    Last edited by Azuleturtle; 06-05-2006 at 09:53 PM.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    if (currentDate > thisTableDate) {

    But you have another problem here... id may not begin with a digit, it must have as first character a letter or an underscore. So that you must re-think your code according to this specification.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Obviously, I forgot about that. I put in a substring. But, it's still not doing what I want it to. Which is to show the current and future dates by table id. Any thoughts???


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>

    <script type="text/javascript">

    window.onload = init;
    var serverDate = "<!--#config timefmt="%m/%d/%Y"--><!--#echo var="DATE_LOCAL" -->";

    function init() {
    hideOldDays();
    }//

    /* --------------------------------------------------------------------------------------

    -----------------------------------------------------------------------------------------*/

    function GetDay(intDay){
    var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday")
    return DayArray[intDay]
    }

    function GetMonth(intMonth){
    var MonthArray = new Array("January", "February", "March",
    "April", "May", "June",
    "July", "August", "September",
    "October", "November", "December")
    return MonthArray[intMonth]
    }

    function getDateStrWithDOW(){
    var today = new Date()
    var todayStr = GetDay(today.getDay()) + ", "
    todayStr += GetMonth(today.getMonth()) + " " + today.getDate()
    todayStr
    return todayStr
    }

    function hideOldDays() {

    var currentDate = new Date(serverDate);
    var tables = document.getElementsByTagName("TABLE");
    for (var i=0; i<tables.length; i++) {
    var t = tables[i];

    var dateStr =t.id.substr(5)
    var thisWeekDate = new Date(dateStr);
    if (currentDate > thisWeekDate) {
    document.getElementById(t.id).style.display = "none";
    }
    }
    }//

    </script>

    </HEAD>
    <BODY>
    <h3>Today is <SCRIPT Language="JavaScript">
    <!-- hide from old browsers
    document.write(getDateStrWithDOW())
    //--></h3>
    </SCRIPT>
    <br><br>
    <table id="date-05-31-2006" class="">
    <tr><th colspan="2">Wednesday 31</th></tr>
    <tr>
    <td>A</td>
    <td>B</td>
    </tr>
    </table>

    <table id="date-06-04-2006" class="">
    <tr><th colspan="2">June 4</th></tr>
    <tr>
    <td>A</td>
    <td>B</td>
    </tr>
    </table>


    <table id="date-06-05-2006" class="">
    <tr><th colspan="2">June 5</th></tr>
    <tr>
    <td>A</td>
    <td>B</td>
    </tr>
    </table>


    <table id="date-07-06-2006" class="">
    <tr><th colspan="2">June 6</th></tr>
    <tr>
    <td>A</td>
    <td>B</td>
    </tr>
    </table>

    <table id="date-12-07-2006" class="">
    <tr><th colspan="2">June 7</th></tr>
    <tr>
    <td>A</td>
    <td>B</td>
    </tr>
    </table>

    </body>
    </html>
    Last edited by Azuleturtle; 06-05-2006 at 09:54 PM.

  • #4
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    your substring call is returning "date-"

    You need:

    t.id.subtring(5,t.id.length);


  •  

    Posting Permissions

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