hi all,
my java servlet code has a foreach loop which automatically generates a
HTML table with x number of rows.
now my problem is that I would like the rows to be alternating in
colour so that its a lot more easier to read. i have tried to implement
a few approaches but everytime it fails.
can somebody help me out with us and suggest a solution.
thanks. 6 2427
i have a foreach loop in my HTML code which takes a java variable and
for each instance of that variable generates a tr within my table. now
if i hardcode the background for the tr it happens to every single row.
i want to alternate the row colours so that the table rows are a lot
more easier to read. hope this clarifies my question.
<sc*****@gmail. com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. . i have a foreach loop in my HTML code which takes a java variable and for each instance of that variable generates a tr within my table. now if i hardcode the background for the tr it happens to every single row. i want to alternate the row colours so that the table rows are a lot more easier to read. hope this clarifies my question.
Almost anything can be fixed with an if statement.
Use a string variable to hold the color.
And before you use it in the tr tag, have an if statement something like
this
if (theColor.equal s("red")){
theColor = "blue";
}else{
theColor = "red";
}
theString = "<tr style='backgrou nd-color:" + theColor + "'>";
----or something along those lines ----
BTW this is a javascript group - and javascript is not java
Hal Rosser wrote: <sc*****@gmail. com> wrote in message news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
i have a foreach loop in my HTML code which takes a java variable and for each instance of that variable generates a tr within my table. now if i hardcode the background for the tr it happens to every single row. i want to alternate the row colours so that the table rows are a lot more easier to read. hope this clarifies my question.
Almost anything can be fixed with an if statement. Use a string variable to hold the color. And before you use it in the tr tag, have an if statement something like this
if (theColor.equal s("red")){ theColor = "blue"; }else{ theColor = "red"; }
theString = "<tr style='backgrou nd-color:" + theColor + "'>"; ----or something along those lines ----
That logic is not going to achieve what the OP wants. It will change
all red rows to blue, and everything else to red.
The usual way to do it is to either use the row index or keep a count of
the rows. Then evaluate the index/counter mod 2 - if it's zero, set it
to the 'even' colour; otherwise set it to the 'odd' colour.
--
Zif
wrote on 23 jan 2006 in comp.lang.javas cript: hi all, my java servlet code has a foreach loop which automatically generates a HTML table with x number of rows. now my problem is that I would like the rows to be alternating in colour so that its a lot more easier to read. i have tried to implement a few approaches but everytime it fails. can somebody help me out with us and suggest a solution. thanks.
var myTable = document.getEle mentById('myTab le');
var rws = myTable.getElem entsByTagName(" tr");
for(var i=0;i<rws.lengt h;i++)
rws[i].style.backgrou ndColor=(i%2==0 )?"red":"green" ;
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress) sc*****@gmail.c om wrote: my java servlet code has a foreach loop which automatically generates a HTML table with x number of rows. now my problem is that I would like the rows to be alternating in colour so that its a lot more easier to read.
While it would be possible easily with CSS3 Selectors (Last Call Working
Draft) --
tr:nth-child(odd) {
background-color:red;
color:black;
}
tr:nth-child(even) {
background-color:blue;
color:white;
}
-- you should ask in a newsgroup dealing with _Java_ to have those rows
formatted as generated by your servlet (probably involving CSS classes
and the above CSS color properties). Surely you also want those rows
in alternating color when client-side script support is not available.
PointedEars
Thomas 'PointedEars' Lahn wrote on 16 feb 2006 in comp.lang.javas cript: sc*****@gmail.c om wrote:
my java servlet code has a foreach loop which automatically generates a HTML table with x number of rows. now my problem is that I would like the rows to be alternating in colour so that its a lot more easier to read.
[....] Surely you also want those rows in alternating color when client-side script support is not available.
This being a javascript NG however, try:
x = document.getEle mentById('mytab le').tBodies[0].childNodes;
i = 0; while (i< x.length)
x(i).style.back groundColor = (i++ % 2) ? '#faa' : '#aaf';
or, using classes:
x = document.getEle mentById('mytab le').tBodies[0].childNodes;
i = 0; while (i< x.length)
x(i).className = (i++ % 2) ? 'redRow' : 'blueRow';
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: aznFETISH |
last post by:
I have a list of links that I ue on my page, I alternate background colors
for these links in a table, I usually do it using a DB but this list of link
is manually added into the page so my question, is it possible to alternate
the row colors automatic and have it created from a list of URL's?
|
by: Els |
last post by:
Hi,
I would like an opinion on the following:
I have a page which is made up of background-images with transparent
linked images in front of it, which on hover show text in CSS popups.
Due to appropriate alt text, anyone viewing the page with images
turned off, will see the alt text instead, and on hover will see the
popups.
|
by: Peter Williams |
last post by:
Hi All,
I want to write some javascript for a html page which does the
following.
Imagine that the page contains a table with 2 columns and 3 rows, e.g.:
+---+---+
| A | B |
+---+---+
|
by: Doug Laidlaw |
last post by:
I tried to grab an image from a Web page the other day. It turned out that
the page was made up of three horizontal bands, and part of the image was
in each. One band was a JPEG, another was a GIF and I have forgotten what
the main page was.
Apart from lining up the parts of the image, there was no discrepancy in
colours between the two formats. Is that what "Web-safe" means? I thought
that it just meant that the colours would be the...
|
by: Matt B |
last post by:
I have a need to alternate output row colour where not every row in the
sequence is output, so I cannot base the colour on whether position() is odd
or even.
e.g.
....
<xsl:for-each select="result">
<xsl:if test="@status = 'Pass'">
<tr><td>@name</td></tr>
</xsl:if>
<xsl:for-each>
| |
by: sconeek |
last post by:
Hi all,
I am generating a html based table with multiple rows of data coming
in real time from a postgres DB. The underlying technology is java
based however the front end is html.
now i am unable to alternate the colour of every row so that the table
is lot more readable. can anyone suggest a javascript or even a css
script which will alternate the row colours irrespective of the number
of rows.
|
by: Eric Lindsay |
last post by:
I am trying to understand the differences between and uses of
persistent, default and alternate styles. I have read
http://www.w3.org/TR/REC-html40/present/styles.html section 14.3.2 on
specifying external style sheets in link using combinations of rel and
using or not using the title attribute.
I think I sort of understand rel="alternate stylesheet". It seems to be
able to act something like the media="print" or media="handheld" or...
|
by: Charles Law |
last post by:
Ok. I haven't been around for a while, so I hope someone will come to my
rescue. I thought I had done this years ago, but I have scoured my code
snippets and can't find it.
I want my ListView control to have a different background colour on
alternate rows. I'm using VS2005.
Firstly, I'm surprised that I can't do it out of the box. But secondly, I
can't find a really simple one-liner that let's me do it by overriding
something.
|
by: Jameson |
last post by:
Hi,
I have a list of known colours, generated using:
Dim colorNames As New System.Collections.Generic.List(Of String)
For Each known As KnownColor In .GetValues(GetType(KnownColor))
Dim specific As Color = Color.FromKnownColor(known)
|
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...
|
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,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |