You are here: Re: problem with spaces « PHP Programming Language « IT news, forums, messages
Re: problem with spaces

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( &quot;english&quot;, &quot;' . $myrow[ 'word_english' ] . '&quot; )">click here</div>';

which outputs (also correct):

<div onclick="change_text( &quot;english&quot;, &quot;dark blue&quot; )">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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация