This is a discussion on javascript and php within the alt.comp.lang.php forums, part of the PHP Programming Forums category; How do I integrate javascript within a php script? I am trying to integrate a headline grabber (moreover) into a ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
How do I integrate javascript within a php script? I am trying to integrate
a headline grabber (moreover) into a web page that is generated using php. I have searched the web but am having difficulty finding a definitive answer. -- Regards, John |
|
|||
|
"John Gelavis" <admin@tnet.com.au> wrote in message news:3fde75ff$0$31746$c30e37c6@lon-reader.news.telstra.net... > How do I integrate javascript within a php script? I am trying to integrate > a headline grabber (moreover) into a web page that is generated using php. > > I have searched the web but am having difficulty finding a definitive > answer. > > -- > Regards, > > John > > You have to realize what is going on - on the server. PHP is processed BEFORE rendering HTML pages to the client (browser) JavaScript is executed AFTER this by the client. So, any PHP output that you send will be created inside of the HTML stream and sent to the browser. So, Something like this # file test.php <html> <body> <?php echo "<script language='javascript'>"; echo "alert ("Hello World");"; echo "</script>"; ?> </body> </html> is seen by the browser as <html> <body> <script language='javascript'> alert ("Hello World"); </script> </body> </html> The browser has no clue that PHP rendered the page, nor does it care. It will just display the page and the alert. |
|
|||
|
xyzzy ha scritto:
> You have to realize what is going on - on the server. > PHP is processed BEFORE rendering HTML pages to the client (browser) > JavaScript is executed AFTER this by the client. > So, any PHP output that you send will be created inside of the HTML > stream and sent to the browser. > > So, > > Something like this > # file test.php > <html> > <body> > <?php > echo "<script language='javascript'>"; > echo "alert ("Hello World");"; > echo "</script>"; >> > </body> > </html> You might want to do: <html> <body> <?php echo '<script language="javascript"> alert ("Hello World"); </script>'; ?> </body> </html> Take a look at quotes, especially (" => ' if there are not variable or things like \n to parse). > is seen by the browser as > > <html> > <body> > <script language='javascript'> > alert ("Hello World"); > </script> > </body> > </html> > > The browser has no clue that PHP rendered the page, nor does it care. > It will just display the page and the alert. A. -- My homepage http://antoniobonanno.debris.it/ My portfolios http://www.debris.it/whois.php?i=6 http://www.usefilm.com/photographer/19053.html http://www.photosig.com/go/users/view?id=99395 |
|
|||
|
If you're wondering how to interchange the variables between JavaScript and
PHP, i.e.: <Javascript section ... some code.. --> here you need to read a php variable (see php section below) var x=document.getElementbyId("myElement").value > ### <?php section ... some code.. ?> <input type="hidden" name="myElement" value=" <?php echo "$myvar"; ?> "> hidden type is used in order to make it unvisible on the screen. I do not really know how to make it work the other way, i.e. PHP reading vars from JScript, since PHP's processed first on the server and once it's done there's only HTML code and JScript left. Hope it was clear and close to your question. "John Gelavis" <admin@tnet.com.au> wrote in message news:3fde75ff$0$31746$c30e37c6@lon-reader.news.telstra.net... > How do I integrate javascript within a php script? I am trying to integrate > a headline grabber (moreover) into a web page that is generated using php. > > I have searched the web but am having difficulty finding a definitive > answer. > > -- > Regards, > > John > > |
![]() |
| Thread Tools | |
| Display Modes | |
|
|