...

View Full Version : Showing new Date() and future dates



Azuleturtle
06-03-2006, 04:07 AM
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>

Kor
06-05-2006, 02:22 PM
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.

Azuleturtle
06-05-2006, 08:50 PM
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>

Beagle
06-05-2006, 09:03 PM
your substring call is returning "date-"

You need:

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum