Hi, have some code that uses PHP/HTML and a Javascript function to display 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 a cell ID 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 that an attempt to develop that code into having a choice of cell. Can anyone see where i’m going wrong?
p.s I already posted this in the JS forum but nobody touched it, I therefore assume it’s more of a PHP problem. Sorry if this construed as spamming.
[B]Original working code:-
<html>
<head>
<title>test</title>
</head>
<body>
<?php
$text = ‘some words about the bbc’;
echo “<a href=’$address’ onmouseover=’test(" $text " )’>bbc</a>”;
?>
<table border=”1″ cellpadding=”0″ cellspacing=”0″ width=”70%”>
<tr>
<td width=”50%” id=”one”>one</td>
<td width=”50%” id=”two”>two</td>
</tr>
<tr>
<td width=”50%” id=”three”>three</td>
<td width=”50%” id=”four”>four</td>
</tr>
</body>
<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>
<html>
[B]Developed code that doesn’t work: –
<html>
<head>
<title>test</title>
</head>
<body>
<?php
$text = ‘some words about the bbc’;
[B]$cellID = ‘three’;
echo “<a href=’$address’ onmouseover=’test(" $text ",[B] " $cellID "
?>
<table border=”1″ cellpadding=”0″ cellspacing=”0″ width=”70%”>
<tr>
<td width=”50%” id=”one”>one</td>
<td width=”50%” id=”two”>two</td>
</tr>
<tr>
<td width=”50%” id=”three”>three</td>
<td width=”50%” id=”four”>four</td>
</tr>
</body>
<script type=”text/javascript”>
function test(someText, [B]cellID
var e = document.getElementById([B]cellID
while(e.firstChild)e.removeChild(e.firstChild);//clear contents
e.appendChild(document.createTextNode(someText));
}
</script>
<html>