Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 30th, 2005, 10:06 PM
Registered User
 
Join Date: Nov 2005
Location: Phoenix, AZ, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP & JavaScript variables?

Can PHP and JavaScript write to variables that each can share?

For example, if I define a variable with a JavaScript, can I use that variable with a PHP script? ...and vice-versa?

Thanks!

Mike L
Reply With Quote
  #2 (permalink)  
Old November 30th, 2005, 10:13 PM
Registered User
 
Join Date: Nov 2005
Location: Phoenix, AZ, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ooops... Sorry, I accidentally posted to the wrong heading.

Reply With Quote
  #3 (permalink)  
Old November 30th, 2005, 10:16 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Not exactly. You have to keep in mind that PHP runs on the server, and JavaScript on the client-side. So sharing may not happen in the way you may expect. JavaScript can only send variables to PHP via POST (as in a form submission), GET (form submission, or URL query string), or COOKIE. PHP can create and output JavaScript, so you would merely generate JavaScript as you would HTML to send PHP variables to JavaScript. For example:

Code:
<?php

$hello = 'Hello, world!';

echo "<script type='text/javascript'>\n".
     "    var \$hello = '{$hello}';\n".
     "    alert(\$hello);\n".
     "</script>\n";

?>
HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP & JavaScript variables? mlewitz Beginning PHP 2 December 2nd, 2005 08:18 AM
Passing PHP variables to javascript wfrisch Pro PHP 10 April 5th, 2005 05:13 AM
Javascript & PHP rajuru Beginning PHP 6 February 22nd, 2005 06:15 AM
passin javascript variables to another page in php ismnanie Javascript 0 January 26th, 2005 01:24 AM
Q. How do I pass PHP variables to JavaScript? Snib PHP FAQs 0 April 8th, 2004 11:34 AM



All times are GMT -4. The time now is 01:05 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.