javascript from php doesn't work

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi All,

I tried a javascript function in a php form but the code doesn't seem
to work.

I have the following javascript function:

<SCRIPT language="JavaScript">
function bcolor(bcol,d_name)
if (document.all)
 var thestyle= eval ('document.all.'+d_name+'.style');

It should change the backgroundcolor of a cell in a table.

Now running this from within php:

First I draw the cell:
echo "<td ID=\'$the_day\' valign=\"top\" class=\"kaltexr\" onclick=
$this_year'\" onMouseOver=\"'#E9ECEF';\"
onMouseOut=\"'#CDD2D9'\" bgcolor=#CDD2D9><b>

Then if it matches my query I want to chane the backgroundcolor of the
if (mysql_num_rows($result) >= 1)
     echo "<font style=\"color: black; font-size:90%; font-family:
Verdana, Arial, Helvetica, sans-serif;\"><center><b>";
  while ($row = mysql_fetch_array($result))
     echo "<SCRIPT LANGUAGE='javascript'>bcolor('green','$the_day');</
         echo "".$row['titel']."";
          echo "</b></center></font><br>";

But nothing happens.
Also the 'title from $row doesn't show anymore.


Re: javascript from php doesn't work

Co wrote:

Quoted text here. Click to load it
I smell badly escaped single quotes. Please run your resulting webpage
through a HTML validator.

Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

Aviso: Este e-mail es confidencial y no debería ser usado por nadie que no
sea el destinatario original. No se permite la reproducción mediante
fotocopia, walkie-talkie, emisora de radioaficionado, satélite, televisión
por cable, proyector, señales de humo, código morse, braille, lenguaje de
signos, taquigrafía o cualquier otro medio. Bajo ningún concepto debe
traducirse al francés este e-mail. Este e-mail no puede ser ridiculizado,
parodiado, juzgado en una competición, o leído en voz alta con un acento
gracioso llevando un bigote falso y/o cualquier tipo de sombrero,
incluyendo pero no limitándose a pañuelos. No inciten ni provoquen a este
e-mail. Si está medicándose, puede experimentar nauseas, desorientación,
histeria, vómitos, pérdida temporal de la memoria a corto plazo y malestar
general al leer este e-mail. Consulte a su médico o farmacéutico antes de
leer este e-mail. Todas las modelos descritas en este e-mail son mayores de
18 años. Si ha recibido este e-mail por error es probablemente porque
estaba bebiendo cuando escribí la dirección del destinatario.

Re: javascript from php doesn't work

On 13 feb, 20:55, Iv=E1n S=E1nchez Ortega <ivansanchez-...@rroba-> wrote:
Quoted text here. Click to load it

OK, so I did, got about 160 errors.
What did I do wrong here?
Should there be double-quotes instead of single ones?


Re: javascript from php doesn't work

Quoted text here. Click to load it

Please read about HEREDOC in the manual.
It makes your life so much easier. You can skip ALL the stu**d quotes

"Heredoc text behaves just like a double-quoted string, without the
double quotes. This means that quotes in a heredoc do not need to be
escaped, but the escape codes listed above can still be used.
Variables are expanded, but the same care must be taken when
expressing complex variables inside a heredoc as with strings.

echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some .
This should print a capital 'A': \x41


Re: javascript from php doesn't work

Co wrote:
Quoted text here. Click to load it

I'll echo the HEREDOC recommendation - it's much easier.  But what about
your users who have javascript disabled?

You were told earlier how to fix your script the right way.  Get all of
the information first, then build your page.  You are making things
needlessly complicated and putting more requirements on your user.

Do it right - and you don't have to do it over!

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: javascript from php doesn't work

Co wrote:
Quoted text here. Click to load it

Once again - DO NOT depend upon the client to paint the page correctly
using client-side scripting.  Your users may have client-scripting
disabled.  Pull the data - and paint it correctly from the server side.

As Jerry stated - do it right the first time and you won't have to do it

Site Timeline