I have 2 pages, one PHP and one Javascript.
I’d like to pass the variable from this PHP script on one page:
$strFind="SELECT * FROM cometchat_chatrooms_users WHERE userid=$curmemid";
$result=mysql_query($strFind) or die(mysql_error());
$row=mysql_fetch_array($result);
$room=$row['chatroomid'];
to this Javascript on another page:
var timestamp = 0;
var currentroom = $room;
var heartbeatTimer;
var minHeartbeat = 3000;
var maxHeartbeat = 12000;
How can I do this?
You cannot actually “pass” a variable anywhere. But only a scalar value. Frankly, you can pass only text data.
So, in case of javascript you have 2 options:
To generate whole js code from PHP along with all it’s variables. Much like to how you generate HTML.
To request some variable from JS running in a browser, using AJAX technique.