Click to See Complete Forum and Search --> : Changing the bgcolor in a table's cell attributes


olivier
07-31-2006, 03:18 AM
My website contains a listing of public holidays for all the countries of the world. Each page lists the holidays for one country. For an example, see Switzerland (http://www.qppstudio.net/bankholidays2006/switzerland.htm).

What I would like to do, using javascript, is to change the bgcolor of any row that corresponds to today's date (as seen by user's PC, not the server). Specifically, change the html text bgcolor="#FFF9DF" to something else, at specific locations of my page's code.

So for example, tomorrow (August 1) is a holiday in Switzerland, so I would like the bgcolor of that row to be a different color (say light pink) whenever that page is seen on August 1.

Any help would be greatly appreciated.

Best regards,

Olivier

Kor
07-31-2006, 03:31 AM
my FireFox sees nothing on that url... It looks like you used FronPage's themes, or other IE only things like that. There might be a javascript solution for that, but, considering the fact that you used a non-standard way to build a page, at least I can not help you.

I strongly advice you to build pages which can be seen by everyone, on every browser. At least information and navigation issues must be available for everyone.

olivier
07-31-2006, 09:01 AM
my FireFox sees nothing on that url...

Sorry about that, but the world holidays business is cut-throat and too many sites used Mozilla and Opera to steal all our intellectual property in the past. So I have had to, with regrets, exclude Mozilla and Opera visitors. I wish there was another solution, but we have just spent too much time and money getting our data just right to let it be hacked away.

Anyways, I have re-uploaded that particular file, without protection against Mozilla. You can view it at Switzerland (http://www.qppstudio.net/bankholidays2006/switzerland.htm) .

Basically (if you can forgive me for the Mozilla ban :o) I have a standard HTML table with the following excerpt:

... bgcolor="#FFF9DF">

What I would like to be able to do, is to insert a function instead of the color #FFF9DF, a function that checks if the viewer's PC date is the same as the date of that row's holiday, for example for Switzerland on August 1, 2006, and then returns a color calculated in that function:

... bgcolor="getBackColor('2006-08-01')">

Sorry for the strange way I might have written this; I usually work in C++ where such stuff is so easy, but I am having a lot of difficulties doing the simplest things in Html and Javascript. :(

James Gatka
07-31-2006, 10:31 AM
- - - - - - -

Kor
07-31-2006, 10:36 AM
It woun't work, James. You were not attentive, but olivier use not plain text for dates (he believes that it would prevent this the copying of the site... (he, this is only an illusion, if someone wants by all mean to copy something from your page, it will do it by all means). He uses a function which unescape some escaped codes, which makes things very difficult.

I tried also a RegExp solution, but I have been stuck on those unescapes. Sorry olivier, if you would have had a normal web page, I could have helped you. Thus things go much too intricate to worth...

olivier
07-31-2006, 11:55 AM
Thank you very much to all for your comments and the time taken to try to help me. I really appreciate it. (BTW I have removed the Mozilla protection from all pages :cool: )

olivier use not plain text for dates He uses a function which unescape some escaped codes, which makes things very difficult
I can easily change the html code that my program generates to include a date number in clear format (not unescaped). For example I could add a private tag like <qppdate=#####> where #### is some number that corresponds to the date. Would that help ?

It seems that my "simple" question is much more complex than I thought. But the effect would be nice on the website, I believe, so I'd be willing to pay (within reason) if anyone wants to take charge of my query.

James Gatka
07-31-2006, 11:59 AM
Hint: Address people by NAME.

vwphillips
07-31-2006, 02:38 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
// by Vic Phillips (31-July-2006)

var zxcToDay=new Date();
var zxcMonthAry=['January','February','March','April','May','June','July','August','September','October','November',' December'];

function zxcCkDate(zxcid,zxccolor){
var zxcrows=document.getElementById(zxcid).rows;
var zxcdate=zxcToDay.getDate();
var zxcmonth=zxcToDay.getMonth();
for (var zxc0=0;zxc0<zxcrows.length;zxc0++){
var zxccol=zxcrows[zxc0].cells[0].innerHTML.split(' ');
for (var zxc0a=0;zxc0a<zxcMonthAry.length;zxc0a++){
if (zxccol[1]==zxcMonthAry[zxc0a]){zxccol[1]=(zxc0a<10)?'0'+zxc0a:zxc0a+''; }
}
if ((zxccol[1]+((zxccol[2]<10)?'0'+zxccol[2]:zxccol[2]))==((zxcmonth>9)?zxcmonth:'0'+zxcmonth)+((zxcdate>9)?zxcdate:'0'+zxcdate)){
zxcrows[zxc0].style.backgroundColor=zxccolor;
}
}
}
/*]]>*/
</script></head>

<body onload="zxcCkDate('T1','red')">
<table id="T1" cellpadding="0" cellspacing="1" border="1">
<tr>
<td>Sun July 30 </td>
</tr>
<tr>
<td>Mon July 31 </td>
</tr>
<tr>
<td>Tue August 1 </td>
</tr>
</table>
</body>

</html>

Kor
07-31-2006, 03:06 PM
Hint: Address people by NAME.
You mean what? To whom were you talking? Nor your post was polite enough, and you did the same mistake - no address and no name to talking with...

On the other hand, auto-deleting your posts was of no help for anyone.