|
|
|
|
![]() ![]() |
Oct 23 2007, 02:01 PM
Post
#1
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 24 Joined: 9-August 07 Member No.: 23,954 |
Right i had a look across the internet as well as a search on here but you cannot search for anything less than 3 characters. But this is a really quick question.
Would the following code allow me to send a php variable to a javascript? CODE <?php
$color = "green"; ?> <script language="JavaScript"> BackColor= "<?php echo($color);?>"; </script> |
|
|
|
Oct 23 2007, 03:02 PM
Post
#2
|
|
|
Premium Member Group: [HOSTED] Posts: 393 Joined: 9-March 07 From: Tucson, AZ Member No.: 20,794 |
I don't think this is possible...php and javascript are handled by two different preprocessors, one of them is php, the other is handled by the servlet engine. There may be a way to do it specifically using Tomcat and php installed into Tomcat, try the documentation...but as far as doing it with apache and the tomcat redirector...you may be out of luck.
|
|
|
|
Oct 23 2007, 03:27 PM
Post
#3
|
|
|
Absolute Newbie Group: Admin Posts: 888 Joined: 20-February 05 From: Indianapolis, Indiana, USA (Midwest) Member No.: 2,714 myCENTs:35.43 |
In short, yes!
there is no reason for this not to work. In fact, you could have PHP dynamically generate an entire JavaScript on the fly if you wanted. This is because PHP is parsed on the server so the browser only sees the output and JavaScript is parsed in the browser so what ever the browser sees, JavaScript can do... Here is what your PHP code would output: CODE <script language="JavaScript"> BackColor= "green"; </script> Now if you wanted JavaScript to send variables back to PHP, there is some issues but depending on what you want, this could be done using either the POST or GET method of variable passing but usually requires a new page to be loaded. It is possible with AJAX to pass variable to and from the server without the need for a new page load but that is another discussion. vujsa |
|
|
|
Oct 23 2007, 04:21 PM
Post
#4
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 24 Joined: 9-August 07 Member No.: 23,954 |
Okay groovy thanks people. Thats exactly what i wanted.
|
|
|
|
Oct 24 2007, 04:04 AM
Post
#5
|
|
|
Super Member Group: [HOSTED] Posts: 805 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:46.87 |
Right i had a look across the internet as well as a search on here but you cannot search for anything less than 3 characters. But this is a really quick question. Would the following code allow me to send a php variable to a javascript? CODE <?php $color = "green"; ?> <script language="JavaScript"> BackColor= "<?php echo($color);?>"; </script> Yes, it works fine. I do this kind of things every time. Best regards, |
|
|
|
Nov 22 2007, 09:59 AM
Post
#6
|
|
|
Newbie [ Level 1 ] Group: Banned Posts: 7 Joined: 22-November 07 Member No.: 26,356 |
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 5th December 2008 - 12:30 PM |