|
Posted by Hilarion on 07/12/05 13:22
> I've got it down to this, but now it's not php, now I think it's a
> javascript problem, but I still don't have it figured out...
>
> <script language="JavaScript">
> function change_text(id,str) {
> document.getElementById(id).innerHTML=str
> }
> </script>
>
> <div onclick=change_text("num1","word word")>click here</div>
This "<div>" lacks quotes around "onclick" attribute value.
Try this:
echo '<div onclick="change_text( \'english\', \'' . $myrow[ 'word_english' ] . '\' )">click here</div>';
should output correct HTML/JavaScript:
<div onclick="change_text( 'english', 'dark blue' )">click here</div>
or this:
echo '<div onclick=\'change_text( "english", "' . $myrow[ 'word_english' ] . '" )\'>click here</div>';
should output (also correct):
<div onclick='change_text( "english", "dark blue" )'>click here</div>
or this:
echo '<div onclick="change_text( "english", "' . $myrow[ 'word_english' ] . '" )">click here</div>';
which outputs (also correct):
<div onclick="change_text( "english", "dark blue" )">click here</div>
You can also split the code to:
$onclick = 'change_text( "english", "' . $myrow[ 'word_english' ] . '" )';
echo '<div onclick="' . htmlspecialchars( $onclick ) . '">click here</div>';
which gives same HTML as one before, but is more readable in PHP.
Hilarion
Navigation:
[Reply to this message]
|