| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Registered User
Join Date: Nov 2005
Posts: 57
|
passing a cell ID and text from PHP to JS
Hi, I'm a JS novice but have managed to cobble together some code which displays text in a table cell onmouseover of a link. I have realised that what is actually needed is a choice of table cells for text to be displayed in, therefore i need to pass the cell ID as well as the text to the JS function. Below is the code which I already have, below that is my attempt at resolving the problem described. Any help would be great. <?php $text = 'some words about the bbc'; echo"<table border='0' cellpadding='0' cellspacing='0' width='100%'>"; echo"<tr><td width='50%' id = 'textCell'></td>"; echo"<td width='50%' ></td></tr>"; echo"<tr><td width='50%' ></td>"; echo"<td width='50%' ></td></tr>"; echo"</table>"; ?> <a href="www.bbc.co.uk" onmouseover="test("<? echo $text; ?>"">BBC</a> <script type="text/javascript"> function test(someText){ var e = document.getElementById("textCell");if(!e)return; while(e.firstChild)e.removeChild(e.firstChild);//clear contents e.appendChild(document.createTextNode(someText)); } </script> my attempt to change the code: - <?php $text = 'some words about the bbc'; $cellID = 'one'; $text = 'some words about the bbc'; echo"<table border='0' cellpadding='0' cellspacing='0' width='100%'>"; echo"<tr><td width='50%' id = 'one'></td>"; echo"<td width='50%' id = 'two'></td></tr>"; echo"<tr><td width='50%' id = 'three'></td>"; echo"<td width='50%' id = 'four'></td></tr>"; echo"</table>"; ?> <a href="www.bbc.co.uk" onmouseover="test("<? echo $text; ?>",<? $cellID ?>)">BBC</a> <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> |
|
|
|
![]() |