SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript changing table colours

    hey, this post is more complicated then it sounds... how would i go about changing the background of a row in a table that has colums when a check box is clicked...i can change the colour of a single column but how can i change all the columns in a row? ive heard about this "get prarentnode" thing but i dont know how to use it =(

    thanks - Phil

  2. #2
    Rehab is for quiters! spartan's Avatar
    Join Date
    Apr 2002
    Location
    Cape Town, South Africa
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just like you would change the colour of the column, but apply the colour change to the <TR> not <TD>, to affect the entire row.
    Spartan
    ---------------------
    It's like our sergeant told us before one trip into the jungle. Men! Fifty of you are leaving on a mission. Twenty-five of you ain't coming back.
    -Mr.Payne

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah i can understand that but how would i go about changing the style of the row with a checkbox event?

  4. #4
    Rehab is for quiters! spartan's Avatar
    Join Date
    Apr 2002
    Location
    Cape Town, South Africa
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    give the <tr> a name <tr name=thisTR id=thisTR> then in the onclick event of the checkbox you put your thisTR.style.background=green or what ever.

    like so....
    Code:
    <table border=1 width=100%>
    <tr name=thisTR id=thisTR>
    	<td>x</td>
    	<td>x</td>
    	<td>x</td>
    	<td><input type=checkbox onclick="javascript:thisTR.style.background='blue'"></td>
    </tr>
    </table>
    and bobs your uncle
    Spartan
    ---------------------
    It's like our sergeant told us before one trip into the jungle. Men! Fifty of you are leaving on a mission. Twenty-five of you ain't coming back.
    -Mr.Payne

  5. #5
    Rehab is for quiters! spartan's Avatar
    Join Date
    Apr 2002
    Location
    Cape Town, South Africa
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oeps. I was just typing, not thinking...

    um.... that will make the colour change, but it won't change back to the original colour when you click on it again.

    so you'll have to write a little function... well depends on what exactly you want to do.

    you could, for example do this
    <input type=checkbox onfocusout="javascript:tr1.style.background='white'" onfocusin="javascript:tr1.style.background='blue'">

    but I'm guessing you want the colour change to happen when the checkbox is checked and unchecked... right?

    then you'll need a function with a if statement to check if the checkbox is on or off and then take apropriate actions.

    hope that helps
    Spartan
    ---------------------
    It's like our sergeant told us before one trip into the jungle. Men! Fifty of you are leaving on a mission. Twenty-five of you ain't coming back.
    -Mr.Payne

  6. #6
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please use the Javascript forum for Javascript questions. You can find it under "Web Page Design".
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the help mate but even that doesnt work

    <input type="checkbox" name="check" value='<%=s("ID")%>' onfocusout="javascript:thisTR.style.backgroundColor='#B7C1CE'">

    is what i have for my checkbox, gave it a name relivant to its place in a database, but when i click on it it doesnt highlight it still... so such luck by the by i did give my <tr> tag a name n id.

  8. #8
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm this is .... odd.... i managed to get your script working when the checkbox didnt have any asp in the <input tag> but with asp in it, it doesnt want to know...exactly the same script used for both checkboxes..one with asp one without... any ideas?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •