Jump to content

[SOLVED] php echo javascript


vurentjie

Recommended Posts

hi,

 

i have a javascript routine that changes the innerHTML of divider,when a button is clicked

this works great,

basic demo to show more or less:

 

<?php
echo "<input type='button' onclick='quickshow(\"".$showthis[0][1]."\",\"".$showthis[0][2]."\",\"".$showthis[0][3]."\");return false;'  name='Show' value='Show' />";
?>

//and a demo javascript func
function quickshow(conta,contb,contc)
{
  var wrap = document.getElementById('contwrap');
  var nucont = "";
  nucont = nucont+"Hi "+conta+"<br/>";
  nucont = nucont+"Today is the "+contb+"<br/>";
  nucont = nucont+"You are "+contc+" days old<br/>";

  wrap.innerHTML = nucont;
}

 

Ok so the above is alright. But now I am trying to invoke something like the following to change the wrapper contents.

<?php
echo "<script>quickshow(\"".$showthis[0][1]."\",\"".$showthis[0][2]."\",\"".$showthis[0][3]."\");</script>";
?>

 

I dont suspect that there should be problems here with client/server side operations. I could be mistaken.

What am I missing here??Why does the function work when assigned to a button event but not when called on its own, if I call...

echo "<script>alert(\"".$showthis[0][1]."\",\"".$showthis[0][2]."\",\"".$showthis[0][3]."\");</script>";

 

this works perfectly ok.

 

advice appreciated.

Link to comment
https://forums.phpfreaks.com/topic/106928-solved-php-echo-javascript/
Share on other sites

cool I will check these out for future use or possible to replace what I have just figured out,

 

I solved my problem, I am running a query and then populating an array in php, which is what I send to the javascript function,

I am populating the array "outside of the html itself", and also way before the body tag,

I figured I would just echo"<script>" near where the query takes place, this seems to be wrong, I need to do it within the html body tags.

 

thanks for the reply

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.