javascript and php

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-16-2003
John Gelavis
 
Posts: n/a
Default javascript and php

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


Reply With Quote
  #2 (permalink)  
Old 12-16-2003
 
Posts: n/a
Default Re: javascript and php


"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.








Reply With Quote
  #3 (permalink)  
Old 12-16-2003
Plasson
 
Posts: n/a
Default Re: javascript and php [OT]

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


Reply With Quote
  #4 (permalink)  
Old 01-02-2004
Pirkka Pirunen
 
Posts: n/a
Default Re: javascript and php

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
>
>



Reply With Quote
Reply


Thread Tools
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

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



All times are GMT +1. The time now is 08:52 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0