/    Sign up×
Community /Pin to ProfileBookmark

PHP to Javascript

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:-[/B]
<html>
<head>
<title>test</title>

</head>
<body>
<?php
$text = ‘some words about the bbc’;

echo “<a href=’$address’ onmouseover=’test(&quot; $text &quot; )’>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: –[/B]
<html>
<head>
<title>test</title>

</head>
<body>
<?php
$text = ‘some words about the bbc’;

[B]$cellID = ‘three’;[/B]

echo “<a href=’$address’ onmouseover=’test(&quot; $text &quot;,[B] &quot; $cellID &quot;[/B])’>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, [B]cellID[/B]){
var e = document.getElementById([B]cellID[/B]);if(!e)return;
while(e.firstChild)e.removeChild(e.firstChild);//clear contents
e.appendChild(document.createTextNode(someText));
}
</script>

<html>

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@DJsACSep 09.2006 — echo "<a href='$address' onmouseover='test("$text", "$cellID")'>bbc</a>";
×

Success!

Help @Solaar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...