how to hilite a row?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

how to hilite a row?

Post by saumya »

i have a table and in the beginnning column I have radio buttons each for a row.Now my problem is,If somebody clicks on a particular radio button then the whole row should get hilited.Is it possible?? Can you guide me, please.
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
With javascript you may check whether a radio button is checked. On that event you may alter the background of the row also (by javascript only).

djot
-
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

but how to know which row??
is there a variable or property of the table specifying the row identity??
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I'm not certain, but I believe you can also put an onclick event handler on the row itself. In that handler, use 'this.style.backgroundColor' to change the colour. You'll need to use fancier javascript to change it back to unhighlighted as well.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Do something like this you could...

Code: Select all

<table>
  <tr onClick="(this.style.backgroundColor == '#ff0000' ? this.style.backgroundColor = '#ffffff' : this.style.backgroundColor = '#ff0000')">
                <td>
	  <input type="radio" name="blah" value="blah">
	</td>
                 <td>
	  Blah
	</td>
  </tr>
</table>
although change the row color back it will not when selecting a different radio button (on a different row) you are.
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

wow, thatworked man.But how to get back the others bg color to normal?? :((
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

for that, you'd have to loop over all of the other rows and turn their background color back to nothing or some other default color. Should be pretty easy to do, just loop the rows first, then change the current row's color to whatever you want.
Post Reply