Can i pass value to javascript from php

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

Threaded View


i need to pass some variables or value to javascript from php script.
well all i need to pass to value to javascript that is with in same
php file the two values r in php i need to pass it to javascript from
there to ext page the following code make clear


$ip = "";
$key = "xxxx";
//javascript that takes two value and post to next frame
<script language="JavaScript">
    function load(ip,key)
parent.rtop.location.href ='updata.php';
    //alert("the update loaded");
parent.right.location.href ='show.php?ips='+ip+':'+key;
//return true;


here how can i call that javascript from php code.


Re: Can i pass value to javascript from php

BigZero schreef:
Quoted text here. Click to load it


$myVar = "Hello JavaScript";
<script type="text/javascript">
  alert('<?php echo $myVar; ?>');

So simply place the values you need at the right place in your output.
Remember that PHP only produces the source for the browser.
So you simply do a 'view source' in your browser to see what PHP produced.

If you need JavaScript to get values from PHP without a pagereload, use

Erwin Moller

Site Timeline