PDA

View Full Version : JS with PHP



asmon
Aug 16th, 2007, 09:58 PM
is it possible using JS inside PHP strings and vice versa?
are there any limitations?

ty.

ess
Aug 16th, 2007, 10:49 PM
Yes...you can declare JS inside PHP and echo it out for example

<?php
$js = '<script>window.alert("Hello World");</script>';
echo $js;
?>

However, you cannot do it the other way around. In other words, if you try, JS will wouldn't have access to the PHP interpretor and as a result, the script will fail.

However, if you use Ajax, you can have JS call PHP script residing on a given server...but, it is not really the same as incorporating JS inside a PHP script if that makes any sense.

Cheers,
Ess

aleminio
Aug 16th, 2007, 11:02 PM
Well, what i need is
- to execute a php code when a JS countdown gets to 0.
- to make a link dissapear when the countdown gets to 0.

guvenck
Aug 17th, 2007, 12:08 AM
I guess I had asked the vice-versa part some time ago.

You can check this thread:

http://www.codingforums.com/showthread.php?t=119897