954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Javascript - Print Date in different color

How can i display the dates that i have in my table in a different color if they were less than today's date?


:confused: ..

Sulley's Boo
Posting Pro in Training
452 posts since Dec 2004
Reputation Points: 529
Solved Threads: 10
 

Since this is a JavaScript question, I assume you want this done completely client-side? We'll be happy to help, but first a couple of observations:

1) This might be easier server-side. How are you generating your pages?

2) The approach will depend on your page structure and doctype. Can you give us a skeleton sample of your HTML?

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

Perhaps this

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

The Date Object would indeed come into play, but the bigger question is how he'll access the "dates" that are in his table. There needs to be a corresponding Date Object for those, or a method to access those via the DOM and move them into a Date Object, before any comparsion could be done.

That's why I pointed toward the server-side solution. My guess is that this is a dynamic, program-generated page, and as such, rather than load the page with JavaScript Date Objects to do client-side, after-the-fact date recognition, he should simply do it server-side while building the page.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

bright_banner.jpgExp. Period: 25.04.00 - 25.04.08 Flight Information System / Record of Airline Aircraft Report Airline - Aircraft Certificate Validity Insurance Validity Add Title Code Name Air Reg. No A.O.C C.O.F.R C.O.F.A HULL Third Party PAX CGO LOAD ACAS TCAS (V7) Total Aircrafts 00 TAV Aviation Joint Stock HS125 TCTAV   05/01/2007   31/10/2006 31/10/2006 31/10/2006 31/10/2006 PAX YES NO 1 000 Salem Aviation Jeddah AN12 11036 01/06/2006 01/07/2006 01/08/2006         PAX NO YES 1 AAP Aerovista Airlines AN24 EX004 15/08/2006 18/12/2006   30/04/2006       PAX YES NO 1 AIN African International Airways DC8 ZSOSI 20/12/2006 10/04/2007   01/04/2007       CGO YES NO 1 ATG Aerotrans Airlines T154 85569 20/11/2007 10/04/2006   21/06/2006 21/06/2006 21/06/2006 21/06/2006 PAX YES NO 1 AZQ Silk Way Airlines IL76 4KAZ41 08/03/2007             CGO YES NO 1 AZV ASOV - AVIA, Air Company IL76 URZVC 16/02/2008 16/02/2008   17/06/2006       CGO YES NO 1 BDS South Asia Airlines Limited B707 S2ADU 15/02/2006   15/07/2006 01/09/2006       CGO YES NO 1  


Date:
 
Time:
 
Page:
 
Print Page
 

Sulley's Boo
Posting Pro in Training
452 posts since Dec 2004
Reputation Points: 529
Solved Threads: 10
 
Perhaps this

you know, i thought that your signature was your reply to my Q .. i was like COMPLETY LOST :confused: .. haha ..

Thanks for the link .. Will try to understand it .. You know I know nothing about Javascript ..

Sulley's Boo
Posting Pro in Training
452 posts since Dec 2004
Reputation Points: 529
Solved Threads: 10
 

Is that code fine? I mean the doctype and all that :o

Sulley's Boo
Posting Pro in Training
452 posts since Dec 2004
Reputation Points: 529
Solved Threads: 10
 

Looks good. You can validate it against w3c.org's validators, to be sure.

Ok, the short answer is that you use CSS to style HTML elements. You could create two CSS classes, one for normal color, and one for "old" dates.

<style type="text/css">
.normal
{
  color: black;
}

.old
{
  color: red;
}
</style>



Something like that, to use a simple example. This goes in your HEAD portion of your document.

Then, to apply the style, add the "class" attribute to your tags:

<td class="normal>normal</td>
<td class="old">old</td>



The trick is, how to do that programmatically? Again, I suggest server-side. There is no one solution, first you have to decide what language you're going to use, and learn the basics of that language.

I suggest PHP. Daniweb has a great PHP forum.

The basic idea is that you create CSS and HTML to control how the page looks, and then you write a PHP program to output the CSS & HTML. At the time the PHP program runs (which is as soon as a user browses to the page), it can enter the dates into the table, check the dates, and add the correct "class" to the table elements.

Daniweb in fact is a big PHP program.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 
Sulley's Boo
Posting Pro in Training
452 posts since Dec 2004
Reputation Points: 529
Solved Threads: 10
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You