passing a cell ID and text from PHP to Javascript

They have: 18 posts

Joined: Mar 2006

Hi, I am new to Javascript but have managed to cobble together some code using PHP/HTML and a Javascript function that displays some text in a table cell on mouseover of a link, a PHP variable contains the text and is passed to the Javascript function on mouseover. The cell that the text is displayed in is constant but i would like to use a choice of cells for the text to be displayed in and therefore pass $cellID to the Javascript function aswell. I have attempted this but am doing something wrong. Below is the code that works for the first scenario described and below is an attempt to develop that code into having a choice of cell. Can anyone see where i'm going wrong?

Original working code:-

test

<?php
$text
= 'some words about the bbc';

echo
"<a href='$address' onmouseover='test(&quot; $text &quot; )'>bbc</a>";
?>

one
two

three
four

<script type="text/javascript">
function test(someText){
var e = document.getElementById("three");if(!e)return;
while(e.firstChild)e.removeChild(e.firstChild);//clear contents
e.appendChild(document.createTextNode(someText));
}
</script>

Developed code that doesn't work: -

test

<?php
$text
= 'some words about the bbc';

$cellID = 'three';

echo
"<a href='$address' onmouseover='test(&quot; $text &quot;, <strong>&quot; $cellID &quot;</strong>)'>bbc</a>";
?>

one
two

three
four

<script type="text/javascript">
function test(someText, cellID){
var e = document.getElementById(cellID);if(!e)return;
while(e.firstChild)e.removeChild(e.firstChild);//clear contents
e.appendChild(document.createTextNode(someText));
}
</script>