vurentjie Posted May 23, 2008 Share Posted May 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/106928-solved-php-echo-javascript/ Share on other sites More sharing options...
jaymc Posted May 23, 2008 Share Posted May 23, 2008 try this window.onload = yourFunction(); or setTimeout("functionName()", 0); I had the same problem Quote Link to comment https://forums.phpfreaks.com/topic/106928-solved-php-echo-javascript/#findComment-548040 Share on other sites More sharing options...
vurentjie Posted May 23, 2008 Author Share Posted May 23, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/106928-solved-php-echo-javascript/#findComment-548043 Share on other sites More sharing options...
vurentjie Posted May 23, 2008 Author Share Posted May 23, 2008 after going over it again, my solution actually wasn quite the thing to do, but after use setTimeOut that seemed to do the trick, thanks a stack, many headaches saved! Quote Link to comment https://forums.phpfreaks.com/topic/106928-solved-php-echo-javascript/#findComment-548071 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.