Jump to content

change color of table row javascript


raman

Recommended Posts

I don't know why I don't get the effect of color change in table rows though I have put everything correctly in my code.I have used the javascript  function bgr_color and then used onMouseOver and onMouseOut attributes for <tr> tag but don't get the effect.My code is as under


<?php
$org=$_POST['Organism'];

$cat=$_POST['Category'];

$con= mysql_connect("localhost.localdomain","root","***");

if(!$con)
  {
    die('Could not connect:'.mysql_error());
  }
else
  {
    echo"<head><script type='text/javascript' src='selctall.jsp'>

</script>
<script type='text/javascript'>
function bgr_color(obj,color) {
    obj.style.backgroundColor=color
}
</script>

</head>";
echo "<h2><div align='center'><font color='green'>Results of your query</font></div></h2><body bgcolor='wheat'>";
}
mysql_select_db("Protvirdb",$con);

echo "<table border='1'><form id='field' action='down2.php' method='post'>
      <tr><th><input type='checkbox' name='checkall' onclick='return selectAll(field);'></th><th>Organism</th>
      <th>Category</th>
      <th>Protein</th>
      <th>Brief Description</th>
      </tr>";
$arry=array();
foreach($_POST['Organism'] as $org){
  foreach($_POST['Category'] as $cat){ 
    $ret=mysql_query("SELECT * FROM cryptovir WHERE Organism='$org' AND Category='$cat'");
    $count=mysql_num_rows($ret);
    $counter+=$count;
    if ($count==0){
      array_push($arry,$cat);
    }
  }
  echo "<div>No records found for categories: ";
  for ($i=0;$i<count($arry);$i++){
    echo"$arry[$i] ";
  }
  echo "for <i>$org</i></div>";
}
echo"<p>The total number of records retrieved by your query is $counter.</p><input type='submit' name='excel' value='Download selected items as excel file.'><input type='submit' name='fasta' value='Download as fasta file'>";

foreach($_POST['Organism'] as $org){
  foreach($_POST['Category'] as $cat){ 
    $ret=mysql_query("SELECT * FROM cryptovir WHERE Organism='$org' AND Category='$cat'");
    $count=mysql_num_rows($ret);
    if($count==0){

    }else {
      //echo"<p> The number of records retrieved by your query is $count</p>";
   
      while($row=mysql_fetch_array($ret))
{
  $ort=$row['Organism'];
  $tre=$row['Category'];
  $key=$row['SNo'];
  
  // echo"<form action='down.php' method='post'>";
  echo "<tr bgcolor='#FFFFFF' onMouseOver='bgr_color(this,'#FF0000')' onMouseOut='bgr_color(this,'#FFFFFF')'>";echo"<td><input type='checkbox' name='pro[]' value=\"$key\"></td>";  
  echo"<td><i>".$row['Organism']."</i></td>";
  echo"<td>".$row['Category']."</td>";
  echo"<td><a href=\"seq2.php?sn=$key\">".$row['Name']."</a></td>";
  echo"<td>".$row['Brief_Description']."</td>";
  echo "</tr>"; 
          
}
    }
  }
  
}
echo"</form></table><br>";


mysql_close($con);
?>

Link to comment
https://forums.phpfreaks.com/topic/131052-change-color-of-table-row-javascript/
Share on other sites

You can't edit your first post anymore only a forum administrator can. It does not have to do anything with your problem but it could create one if someone decided to hack your server.

 

also your problem is not really php related. I suggest you look in your browser source to see what goes wrong and check for javascript errors

I have still not got the answer to my problem.I have checked the error console of the browser.

It shows error as:

 

 

Error: syntax error

Source File: http://localhost/blalnl/que6.php

Line: 1, Column: 15

Source Code:

bgr_color(this,

 

Can someone solve now ?

it's because you're not using your quotes right

 

change

<?php
echo "<tr bgcolor='#FFFFFF' onMouseOver='bgr_color(this,'#FF0000')' onMouseOut='bgr_color(this,'#FFFFFF')'>";
?>

to

<?php
echo "<tr bgcolor='#FFFFFF' onMouseOver=\"bgr_color(this,'#FF0000')\" onMouseOut=\"bgr_color(this,'#FFFFFF')\">";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.