I am displaying data in a table and want to call a Javascript function when the user clicks on one of the cells in the table.

my php code is

while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['Prntr'] . "</td>";
echo "<td> <a href='#' onclick='jumptocartridgex()'>" . $row['Cartridge'] . "</a></td>";
echo "<td>" . $row['Colour'] . "</td>";
echo "<td>" . $row['Type'] . "</td>";
echo "</tr>";
}

The second column shows the correct content and it is displayed as a link however when I click on the cell the script does not run. In addition, if I ever get the script to run, I would like to get the value from $row['Cartridge'] passed to the JS function.

What am I doing wrong?

    How about something like this?

    echo "<td> <a href='#' onclick='jumptocartridgex(\"". $row['Cartridge']."\"); return false;'>" . $row['Cartridge'] . "</a></td>";

      Thanks for that.
      The escape characters were definitely what I needed in the echo statement.

      My real problem was that the function didn't appear to be called at all but it is working today and I think I must have been having some version control problems with the external js file.

      Thanks again.

        Write a Reply...