Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: SV: RE:SV: TD HIGHLIGHT


Message #1 by "Robert Nyman" <robert.nyman@c...> on Thu, 3 Oct 2002 13:46:32 +0200
HI Claudio,
Use this 
i m using "alterTds" as a boolean var for toggling ..
Hope this is simpler to implemet ...
Bye 
Gautam Khanna
gautamkhanna27@y...
*******************************************************************************************

<html>
<head>
<script language="javascript" >
window.onload = Gaurav;
 
function Robert()
{
 var arrTables =document.getElementsByTagName("table");
 for(var i=0; i<arrTables.length; i++){
  var arrAllCurrentTableCells =arrTables[i].getElementsByTagName("td");
  for(var j=0; j<arrAllCurrentTableCells.length; j++){
   var oTD = arrAllCurrentTableCells[j];
   var intValue = parseInt(oTD.innerHTML, 10); 
  //If you're only targetting IE, then exhange innerHTML to innerText
   if(intValue < 50 || intValue > 100){
    oTD.style.color ="white";
    oTD.style.backgroundColor =(intValue <50)? "blue" : "red";
   }
  }
 }
}
 
function Gaurav()
{
var alterTds = false;
 var arrTables =document.getElementsByTagName("table");
 for(var i=0; i<arrTables.length; i++){
  var arrAllCurrentTableCells =arrTables[i].getElementsByTagName("td");
  for(var j=0; j<arrAllCurrentTableCells.length; j++)
  {
   var oTD = arrAllCurrentTableCells[j];
   alterTds = !alterTds;
   var backColor = (alterTds)?"blue":"red";
   oTD.style.color ="white"; oTD.style.backgroundColor =backColor;
  }
 }
}
 
 
 
 
 
</script>
</head>
<body>
<table>
 <tr>
  <td>103</td>
  <td>49</td>
  <td>76</td>
 </tr>
 <tr>
  <td>49</td>
  <td>103</td> 
  <td>76</td>
 </tr>
</table>

<table>
 <tr> 
  <td>49</td>
  <td>76</td>
  <td>103</td>
 </tr>
 <tr>
  <td>76</td>
  <td>49</td>
  <td>103</td>
 </tr>
</table>
</body>
</html>
*******************************************************************************************
 
 Claudio Pallone 
wrote:Hi Gautam, Thanks for your help as well.

You said: "use a Boolean Variable with on/off switch which doesn't require 
any extra headaches of memory processings within the scope..."

Would it be possible for you to alter the code to use this technique(using 
a Boolean variable with on/off switch) so that I can learn how to do it?

Thanks

Claudio 




---------------------------------
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!

  Return to Index