468,249 Members | 1,524 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,249 developers. It's quick & easy.

How to Pass PHP variables to JS?

Don
How do I pass PHP variables to JavaScript in the returned browser page?

Thanks,
Don
Jul 17 '05 #1
6 9567
Don wrote:
How do I pass PHP variables to JavaScript in the returned browser page?

Thanks,
Don

Well, you could do this if you have a variable $_POST['name']:
....
some javascript
.....

echo 'var name = ' . $_POST['name'];

....
Just like HTML, but you write valid javascript.
Jul 17 '05 #2
Don
On Mon, 08 Nov 2004 14:04:37 -0600, David Zawislak <da*******@excite.com> wrote:
Don wrote:
How do I pass PHP variables to JavaScript in the returned browser page?

Thanks,
Don

Well, you could do this if you have a variable $_POST['name']:
...
some javascript
....

echo 'var name = ' . $_POST['name'];

...
Just like HTML, but you write valid javascript.


Thanks David. That worked just fine.

Regards,
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 17 '05 #3
Don wrote:
How do I pass PHP variables to JavaScript in the returned browser page?

Thanks,
Don


<?
$hello = "hello";
?>

<script language="javascript">
alert("<?=$hello;?>");
</script>
Jul 17 '05 #4
In article <1100189674./W3ZIuK13gf7EpV3ROowxg@teranews>,
Jeremy Smith <di******@chl.chalmers.se> wrote:

:<script language="javascript">
:alert("<?=$hello;?>");
:</script>

Or (something useful):

<?php
$referred_to = 'http://127.0.0.1/~you/old_browser.php';
?>

<script language="Javascript" type="text/javascript">
if (!document.getElementById) {
top.location.replace("<?php echo $referred_to; ?>");
}
</script>
--
Looks like more of Texas to me.
.... Arizona, where the nights are warm and the roads are straight.
Jul 17 '05 #5
Don
On Thu, 11 Nov 2004 17:14:31 +0100, Jeremy Smith <di******@chl.chalmers.se> wrote:
Don wrote:
How do I pass PHP variables to JavaScript in the returned browser page?

Thanks,
Don


<?
$hello = "hello";
?>

<script language="javascript">
alert("<?=$hello;?>");
</script>

Thanks Jeremy.
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 17 '05 #6
Don
On Thu, 11 Nov 2004 11:45:39 -0500, Warren Oates <Wa**********@Gmail.com> wrote:
In article <1100189674./W3ZIuK13gf7EpV3ROowxg@teranews>,
Jeremy Smith <di******@chl.chalmers.se> wrote:

:<script language="javascript">
:alert("<?=$hello;?>");
:</script>

Or (something useful):

<?php
$referred_to = 'http://127.0.0.1/~you/old_browser.php';
?>

<script language="Javascript" type="text/javascript">
if (!document.getElementById) {
top.location.replace("<?php echo $referred_to; ?>");
}
</script>

Thanks Warren.
Don
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by adolf garlic | last post: by
10 posts views Thread by tshad | last post: by
7 posts views Thread by Gladen Blackshield | last post: by
6 posts views Thread by lisp9000 | last post: by
12 posts views Thread by Bryan Parkoff | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.