Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.