this is my code to create table with php by looping ..i want to add an onclick function in each ..so that on clicking a particular cell the background color is changed..but m getting an error. m i doing something wrong ??
<head>
<script>
function changeColor(elem)
{
elem.style.background = "red";
}
</script>
</head>
<body>
<?php
$rows = 10; // define number of rows
$cols = 4;// define number of columns
echo "<table border='1'>";
for($tr=1;$tr<=$rows;$tr++){
echo "<tr>";
for($td=1;$td<=$cols;$td++){
echo "<td onclick=\"changeColor(this)\" > ".$tr." ".$td."</td>";
}
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>