Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 10th, 2004, 01:07 AM
Registered User
 
Join Date: Feb 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default JavaScript and php

Hi,
I have problems with javascript in php. Because when I included javaScript to make dynamic forms in page.php, the script did not work correctly. Could you tell me why?
May be I add something for coding to combine javascript and php?
Thanks
Bandy

 
Old February 10th, 2004, 04:26 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can't "combine" javascript and PHP -- not in the way that you're suggesting. PHP and javascript are two different languages, so you can't just include javascript from within PHP and expect it to work.

Beyond that, there's something extremely important that you need to understand -- Javascript is a CLIENT SIDE language (executed on the user's machine in the web browser) and PHP is a SERVER SIDE language (executed on the webserver machine).

PHP is used to generate output. 99% of the time, that output is HTML and/or Javascript. As such, PHP is done executing before a single line of javascript starts executing.

Code:
+--------+          Client sends an HTTP Request   +--------+
| client |   -----> for index.php --->             | server |
+--------+                                         +--------+
                                                        |
                                                 PHP interpreter
                                                 runs index.php
                                                 script, which
                                                 outputs HTML and
                                                 javascript.
                                                        |
                                                        V
+--------+        HTML and Javascript text         +--------+
| client |  <---- output created by index.php ---- | server |
+--------+                                         +--------+
    |
    |
Client web browser
executes javascript
code and renders
the page.
    |
    V
+--------+                                         +--------+
| client |                                         | server |
+--------+                                         +--------+
Notice that when PHP is executing, the client side is just waiting for a response. Also note that when the client is executing the javascript, there is NO connection between the web server and the client -- the server is completely unaware of the client's presence after the output of PHP is sent.


Take care,

Nik
http://www.bigaction.org/
 
Old February 10th, 2004, 04:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now that I've read the posts in your other thread (http://p2p.wrox.com/topic.asp?TOPIC_ID=9560), I realize that either you didn't read the links Rich sent you or they didn't make sense.

If you're having problems with either of these two links, let us know:
  http://p2p.wrox.com/topic.asp?TOPIC_ID=8284
  http://p2p.wrox.com/topic.asp?TOPIC_ID=8040



Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and Javascript davidhayter Beginning PHP 5 May 6th, 2005 05:33 AM
javascript with php kuehhc Beginning PHP 8 February 1st, 2005 10:59 PM
How to use javascript with php? raichand_ray PHP How-To 2 November 12th, 2004 06:41 AM
javascript and php? Ashleek007 Beginning PHP 21 September 23rd, 2004 01:40 PM
PHP with Javascript Droobles Pro PHP 1 February 17th, 2004 03:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.