473,851 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Help Trying to merge 2 Function and CSS to work



I am trying to merge to scripting samples I for on a source code web
site and having limited luck. Then first one is called Zebra Tables
witch colors alternate rows of a table to look beter. The second is a
rule code that highlights the row you are currently moused over. Both
are making use of CSS style sheet to do all of their formating.
My problem is that the rollover is changing the text color but not the
color of the row background as the example does in the original code
which is what I am looking for out of this. Anyone have any ideas???
Link to the Samples are here:
http://www.alistapart.com/articles/zebratables/
http://www.alistapart.com/articles/tableruler/
My Code I have cobbled together

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<style type="text/css">

#mytable {
border: 1px solid #666666;
cellspacing: 0;
}

#mytable thead th,tfoot td{
background-color: #003366;
font-family: "lucida grande", verdana, sans-serif;
font-weight: bold;
color: #ffffff;
font-size: 10pt;
padding: 3px 8px;
}

#mytable tbody tr td {
font-family: "lucida grande", verdana, sans-serif;
font-size: 8pt;
padding: 3px 8px;
border-left: 1px solid #D9D9D9;
}

#mytable tbody tr td.selected {
font-style:italic
font-size: 8pt;
text-decoration:unde rline;
color: #660000;
font-weight: bold;
}
#mytable tbody tr.ruled{
font-size: 11pt;
background:#9cf ;
color: "#ccc";
}
table{
border:1px solid #000;
border-collapse:collap se;
}
</style>
<script type="text/javascript">
<!--
// this function is needed to work around
// a bug in IE related to element attributes
function hasClass(obj) {
var result = false;
if (obj.getAttribu teNode("class") != null) {
result = obj.getAttribut eNode("class"). value;
}
return result;
}

function stripe(id) {

// the flag we'll use to keep track of
// whether the current row is odd or even
var even = false;

// if arguments are provided to specify the colours
// of the even & odd rows, then use the them;
// otherwise use the following defaults:
var evenColor = arguments[1] ? arguments[1] : "#fff";
var oddColor = arguments[2] ? arguments[2] : "#eee";

// obtain a reference to the desired table
// if no such table exists, abort
var table = document.getEle mentById(id);
if (! table) { return; }

// by definition, tables can have more than one tbody
// element, so we'll have to get the list of child
// &lt;tbody&gt ;s
var tbodies = table.getElemen tsByTagName("tb ody");

// and iterate through them...
for (var h = 0; h < tbodies.length; h++) {

// find all the &lt;tr&gt; elements...
var trs = tbodies[h].getElementsByT agName("tr");

// ... and iterate through them
for (var i = 0; i < trs.length; i++) {

// avoid rows that have a class attribute
// or backgroundColor style
if (! hasClass(trs[i]) &&
! trs[i].style.backgrou ndColor) {

// get all the cells in this row...
var tds = trs[i].getElementsByT agName("td");

// and iterate through them...
for (var j = 0; j < tds.length; j++) {

var mytd = tds[j];

// avoid cells that have a class attribute
// or backgroundColor style
//if (! hasClass(mytd) &&
// ! mytd.style.back groundColor) {

mytd.style.back groundColor =
even ? evenColor : oddColor;

//}
}
}
// flip from odd to even, or vice-versa
even = ! even;
}
}
}
// -->
</script>

<script type="text/javascript">
/*
tableruler()
written by Chris Heilmann for alistapart.
enables a rollover of rows for each table with the classname
"hlrows"
*/

function tableruler()
{
if (document.getEl ementById && document.create TextNode)
{
var tables=document .getElementsByT agName('table') ;
for (var i=0;i<tables.le ngth;i++)
{
if(tables[i].className=='ru ler')
{
var trs=tables[i].getElementsByT agName('tr');
for(var j=0;j<trs.lengt h;j++)
{
if(trs[j].parentNode.nod eName=='TBODY')
{

trs[j].onmouseover=fu nction(){this.c lassName='ruled ';return
false}
trs[j].onmouseout=fun ction(){this.cl assName='';retu rn
false}
}
}
}
}
}
}

</script>

<script type="text/javascript">
window.onload=f unction(){table ruler();}
</script>

<html>
<head>
<meta NAME="GENERATOR " Content="SAPIEN Technologies, Inc. PrimalScript
3.1">
<title>Test Page</title>
</head>
<body onload="stripe( 'mytable', '#fff', '#edf3fe');tabl eruler()"><a
name="top"></a>

<div id="bottle">

<h1>Test CSS and Java</h1>

<table class="ruler" id="mytable" >
<thead>
<tr><th scope="col">tes t1</th><th scope="col">tes t2</th></tr>
</thead>
<TBODY>
<tr><td>A</td><td>A</td></tr>
<tr><td>B</td><td>A</td></tr>
<tr><td>C</td><td>A</td></tr>
<tr><td>Dee</td><td>A</td></tr>
<tr><td>E</td><td>A</td></tr>
<tr><td>F</td><td>A</td></tr>
</TBODY>
<tfoot>
<tr><td colspan="2">Sum mary</td></tr>
</tfoot>

</table>
</div>

</body>
</html>
Jul 23 '05 #1
3 1513
On Wed, 14 Apr 2004 10:00:59 -0700, EasyRider41
<tc*****@sempra utilities.com> wrote:
I am trying to merge to scripting samples I for on a source code web
site and having limited luck. Then first one is called Zebra Tables
witch colors alternate rows of a table to look beter. The second is a
rule code that highlights the row you are currently moused over. Both
are making use of CSS style sheet to do all of their formating.
My problem is that the rollover is changing the text color but not the
color of the row background as the example does in the original code
which is what I am looking for out of this. Anyone have any ideas???

Link to the Samples are here:
http://www.alistapart.com/articles/zebratables/
http://www.alistapart.com/articles/tableruler/


Their "ruler" example is flaky on Opera, and both scripts could have been
written better, so I started from scratch. You can see an example here:

<URL:http://www.mlwinter.pw p.blueyonder.co .uk/clj/easyrider/table.html>

As you'll no doubt notice, there's redundancy in the two main functions,
but I'll let you sort that out. I also added a fall-back that will allow
the "ruler" effect to work when JavaScript is disabled[1]: you'll want to
make sure that the colours specified in the "table.rule r tr:hover"
declaration and the initialiseTable Ruler() function are in sync.

[snipped code]

I suggest you validate your HTML before you attempt to script documents,
especially when DOM methods and modification of the document structure is
involved. Invalid documents might not behave as you expect.

<URL:http://validator.w3.or g/>

Hope that helps,
Mike
[1] IE doesn't support the :hover pseudo-class on any element other than
A, so it will rely on JavaScript to provide the ruler effect.

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2
Michael Winter wrote:
<URL:http://www.mlwinter.pw p.blueyonder.co .uk/clj/easyrider/table.html>


A very clear and enjoyable script.

FWIW, here are some suggestions/questions:
- in the CSS declarations, I don't think that you need to use "table
td"-like selectors, "td" only would do; AFAICS you're trying to address
invalid-HTML cases, where we'd have TD elements anywhere - but then
you're telling the OP to fix invalid HTML. Fixing HTML should be enough:-)

- "if( b = tB[ i ]) {" is a bit strange, since you're iterating in the
tBodies collection, the tBody has to exist; have you come across any
implementation in which this wasn't the case?

- "r[ j ].onmouseover = function() {" is declaring a different function
at each iteration; you could declare the function once and then use
reference. Moreover, on a technical note, functions expressions declared
this way could hardly be joined because of scope issues, so if you still
want to declare functions in a loop I'd advise using the Function
Constructor instead, in which case it's easier for implementations to
create joined objects (although not compulsory - a single function, then
references remains the best method).
Regards,
Yep.
Jul 23 '05 #3
On Sat, 17 Apr 2004 11:30:41 +0200, Yann-Erwan Perio
<y-*******@em-lyon.com> wrote:
Michael Winter wrote:
<URL:http://www.mlwinter.pw p.blueyonder.co .uk/clj/easyrider/table.html>
A very clear and enjoyable script.


I actually uploaded the page prematurely. I've uploaded the version that
should have been posted originally (few changes, so there's no point
looking at it again).
FWIW, here are some suggestions/questions:
Always welcome. :)
- in the CSS declarations, I don't think that you need to use "table
td"-like selectors, "td" only would do; AFAICS you're trying to address
invalid-HTML cases, where we'd have TD elements anywhere - but then
you're telling the OP to fix invalid HTML. Fixing HTML should be
enough:-)
Can't say why I did that. The only place where "table" needs to be
included in the selector is with "table.rule r td:hover", to make sure that
non-ruler-enabled tables don't use the effect.
- "if( b = tB[ i ]) {" is a bit strange, since you're iterating in the
tBodies collection, the tBody has to exist; have you come across any
implementation in which this wasn't the case?
That's out of habit: test everything. It shouldn't be needed.
- "r[ j ].onmouseover = function() {" is declaring a different function
at each iteration; you could declare the function once and then use
reference. Moreover, on a technical note, functions expressions declared
this way could hardly be joined because of scope issues, so if you still
want to declare functions in a loop I'd advise using the Function
Constructor instead, in which case it's easier for implementations to
create joined objects (although not compulsory - a single function, then
references remains the best method).


I realised that myself after I uploaded the page. I made the changes to
the local version, but forgot to upload it again. It uses two functions
and assigns references to the handlers.

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1328
by: somaBoy MX | last post by:
I found this function on PHPbuilder.net. It is supposed to colorize a JPEG image by covering it with a transparent colored overlay. I'm trying to implement it, but whatever color value I pass it always it always colorizes the image in greyscale. I'm probably passing the color values incorrectly, but I'm not sure what kind of data the function is expecting. The page where I found the function doesn't provide any solutions. Any help...
0
1817
by: EasyRider41 | last post by:
I am trying to merge to scripting samples I for on a source code web site and having limited luck. Then first one is called Zebra Tables witch colors alternate rows of a table to look beter. The second is a rule code that highlights the row you are currently moused over. Both are making use of CSS style sheet to do all of their formating. My problem is that the rollover is changing the text color but not the color of the row background as...
2
3254
by: Aaron | last post by:
hello, i am perfoming a mail merge with the following code. Public Function MergeIt() Dim objWord As Object Set objWord = GetObject("C:\MyMerge.doc", "Word.Document") ' Make Word visible. objWord.Application.Visible = True ' Set the mail merge data source as the db3 database.
8
5164
by: Darryl Kerkeslager | last post by:
I hope that although this is 25% Access and 75% Word, that someone will know ... The whole problem here arises because 1) Microsoft acknowledges an 'issue' wherein TextInput type FormFields are lost when doing a MailMerge and 2) the fix that they have proposed is both inadequate and won't work from Access. http://support.microsoft.com/?kbid=286841 The part of the code below that actually performs the merge is great; the core of it is...
8
1553
by: mesterak | last post by:
I'm trying to write a text log file processor but am having significant performance issues. * On average, there are about 100-200 files to process each file being about 1MB in size. * Typically there are ~600k to 1m lines to process total. Every line in each log file typically contains a date, a time, follwed by a textual message * Unfortunately, not all log files have the same format/layout; e.g. some may have only have month/day...
0
2775
by: Phil C. | last post by:
Hi, I'm using Access 2000. I have a Select Query that uses the MID function to separate the actual text of articles from the title of the articles. The articles are enterd into the underlying table (in a memo field) in html format, as one big block of text. The memo field is called (I named it before I realized that I needed to separate title from text).
2
1147
by: davidw | last post by:
Hi, I want a xsl so I can categorize a flat xml, like this: <field name="a1"/> <field name="a2" merge="true"/> <field name="a3"/> <field name="a4"/> <field name="a5" merge="true"/> <field name="a6" merge="true"/> <field name="a7"/>
6
2339
by: mike11d11 | last post by:
I'm trying to create an application that will have multiple users working off a table on a SQL server. Since multi users will be updating different records at any given moment, how can i get those changes and merge them into my current Dataset. I've been playing around with the GetChanges method and Acceptchanges but they just dont seem to be pulling over the changes and updating my Dataset. Maybe if someone could give me a sample of...
7
14263
by: Zeba | last post by:
Hi, I have to write program in C# to merge sort a linked list (doubly linked). Is it true that the best way to do it is copy it into an array, sort it and then convert back ? I'm new to C#, but I tried to develop a merge sort program myself, but have got stuck with a Null reference exception for the pos variable in merge function. Also I wrote a function to get the actual nodes from teh index values before calling merge function. Is...
0
2568
by: Egor Zindy | last post by:
Egor Zindy wrote: #!/usr/bin/env python """ A generic chipid library based on ctypes This module handles most of the functions in FTChipID.dll
0
9897
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9747
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10670
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7906
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5933
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4549
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4143
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.