Hi. Is it possible to use PHP code within a javascript funtion? For
example, is the following allowed...
foo( <?php $_SERVER['QUERY_STRING'] ?>);
function foo {
... does something with string
}
Thanks in advance.
Ziggi 4 7676
Ziggi wrote: Hi. Is it possible to use PHP code within a javascript funtion? For example, is the following allowed...
foo( <?php $_SERVER['QUERY_STRING'] ?>);
function foo { ... does something with string }
Yes, here's an example:
test.php:
---------
<html>
<head>
<title>PHP/JS Test</title>
<script type="text/javascript">
function foo($x){
document.write('<font color="red"><b>'
+$x+
'</b></font> was passed to this function.');
return true;
}
</script>
</head>
<body>
<script type="text/javascript">
foo('<?php echo $_SERVER['REQUEST_URI'] ?>');
</script>
</body>
</html>
--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
On Mon, 15 Sep 2003 22:46:50 +0100, "Ziggi" <on*******@hotmail.com> wrote: Hi. Is it possible to use PHP code within a javascript funtion? For example, is the following allowed...
foo( <?php $_SERVER['QUERY_STRING'] ?>);
function foo { ... does something with string }
Thanks in advance.
Yes, but bear in mind that you're just getting PHP to output data that's
inserted literally inside the Javascript.
You can't go on and call a PHP function from a client-side Javascript event.
--
Andy Hassall (an**@andyh.co.uk) icq(5747695) ( http://www.andyh.co.uk)
Space: disk usage analysis tool ( http://www.andyhsoftware.co.uk/space)
Hmm, this code doesn't seem to work. I corrected the mistake in the line
foo('<?php echo $_SERVER['REQUEST_URI'] ?>'), ie escaping the single
quotation marks, but all i got was the line "was passed to this function."
almost as if the $_SERVER['REQUEST_URI'] has not been set... is this a
problem with my server?
Ziggi
"Justin Koivisto" <sp**@koivi.com> wrote in message
news:ly*****************@news7.onvoy.net... Ziggi wrote:
Hi. Is it possible to use PHP code within a javascript funtion? For example, is the following allowed...
foo( <?php $_SERVER['QUERY_STRING'] ?>);
function foo { ... does something with string }
Yes, here's an example:
test.php: --------- <html> <head> <title>PHP/JS Test</title> <script type="text/javascript"> function foo($x){ document.write('<font color="red"><b>' +$x+ '</b></font> was passed to this function.'); return true; } </script> </head> <body> <script type="text/javascript"> foo('<?php echo $_SERVER['REQUEST_URI'] ?>'); </script> </body> </html>
-- Justin Koivisto - sp**@koivi.com PHP POSTERS: Please use comp.lang.php for PHP related questions, alt.php* groups are not recommended.
Ziggi wrote: "Justin Koivisto" <sp**@koivi.com> wrote in message news:ly*****************@news7.onvoy.net...
Ziggi wrote:
Hi. Is it possible to use PHP code within a javascript funtion? For example, is the following allowed...
foo( <?php $_SERVER['QUERY_STRING'] ?>);
function foo { ... does something with string } Yes, here's an example:
test.php: --------- <html> <head> <title>PHP/JS Test</title> <script type="text/javascript"> function foo($x){ document.write('<font color="red"><b>' +$x+ '</b></font> was passed to this function.'); return true; } </script> </head> <body> <script type="text/javascript"> foo('<?php echo $_SERVER['REQUEST_URI'] ?>'); </script> </body> </html>
Hmm, this code doesn't seem to work. I corrected the mistake in the line foo('<?php echo $_SERVER['REQUEST_URI'] ?>'), ie escaping the single quotation marks, but all i got was the line "was passed to this
function." almost as if the $_SERVER['REQUEST_URI'] has not been set... is this a problem with my server?
Well, there was no mistake in the code, I copied and pasted what I
posted and it worked fine. However, you will need to have PHP 4.1 or
greater to use the predefined $_SERVER array. Otherwise use
$HTTP_SERVER_VARS instead.
--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Thomas Parslow |
last post by:
Hi,
I'm using an ASPTemplate class (the one from asptemplate.sourceforge.net) to
produce WAP and HTML verions of the same pages. It seemed to me that it
would be very usefull to have the...
|
by: Steven Scaife |
last post by:
I have decided to re-write the intranet site i created over a year ago. The
coding is pretty awful and hard to read cos I made the mistake of not
putting comments in or putting crappy comments in...
|
by: Kevin Brown |
last post by:
Is there anyway to generate this type of resulting HTML table from
this XML using XSLT? Basically I need to be able to consult 2 trees of
data to generate the HTML, but I have not been able to...
|
by: Frederik S |
last post by:
Hello,
I'm making a nice little login box in Javascript but having problems Posting
the value inside a textfield.
In a nutshell:
I have a function:
function getPostData (value)
|
by: amywolfie |
last post by:
Hi All:
I would like to run a report based on criteria from 3 unbound combo
boxes located on a parameter form (combo boxes are: cboCuisine,
cboLocation, and cboRestaurant)
The present code...
|
by: Johan |
last post by:
Hi all
I'm trying to set the permissions of a file using WMI, and since i'm
writing a windows service i want to use UNC paths doing this because
the destination might not be a mapped path. I'we...
|
by: mike |
last post by:
I have a WebApplication which is consuming a WebService.
Basically the problem I am facing is such that everything is working fine
when I am developing on my local machine. Then I do "Copy Project"...
|
by: Lans Redmond |
last post by:
Is there anyway to connect to a socket via javascript. Im writing an
application where IE on the client pc..needs to connect to a server and get
some information before forward to an action class...
|
by: mast2as |
last post by:
I have posted a few messages in the last few days about a project I am
working on which is a quite simple parser. I ended up using the try/
catch structure as a general mechanism to control what's...
|
by: Ron T. |
last post by:
I've made a table withing my Access file, that lists all the people
that would be allowed to login using the database. The logins and
passwords are logged within the table, and are referred to...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |