Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Call Javascript function from php

I have done many attempts with posts and examples - but I'm unable to understand how to do this. I have this function in the head of my php file:

 .....
 <script type = "text/javascript" language="javascript">
 function agicol() {
 scheduler.clearAll();
 var idname$ = $idencol; 
 scheduler.load("ret_l.php?connector=true&dhx_filter[IDCol]="+idname,ドル"json");
 }
 </script> 
 </head>

And in the body, I use a variable like so:

 <body bgcolor="#C0DFFD" onLoad="init();">
 <?php
 if(isset($_GET['id']))
 {
 $idencol = $_GET['id'];
 echo "<script>alert($idencol);</script>";
 // Alert works properly
 // $idencol contains id sended
 }
 ?>

So, I should call function agicol(), and pass getted id $idencol.

Can someone tell me how?

Thanks in advance

Answer*

Draft saved
Draft discarded
Cancel
3
  • I know there are many method to obtain this result, however is it just impossible to call this function from php code? Commented Nov 24, 2015 at 16:25
  • @Jayelef — Since the PHP executes on a different computer to the JavaScript, yes, it is impossible. You have to deliver the JavaScript to the client and get the client to execute it. Your current approach delivers the JavaScript to the client and then throws away the <head> containing half the code you wanted to execute. Commented Nov 24, 2015 at 16:35
  • Thanks for your explantion @Quentin Commented Nov 24, 2015 at 16:36

default

AltStyle によって変換されたページ (->オリジナル) /