PHP
  Home arrow PHP arrow PHP and JavaScript, Pooling Your Resou...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP and JavaScript, Pooling Your Resources
By: Brian Vaughn
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 34
    2005-09-20

    Table of Contents:
  • PHP and JavaScript, Pooling Your Resources
  • PHP Disguised as JavaScript?
  • You Want More JavaScript?
  • How Does This Work?

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    PHP and JavaScript, Pooling Your Resources


    (Page 1 of 4 )

    As a web programmer, a wide variety of scripting languages are available for you to use. Each language has limitations, but by using more than one in conjunction many of those limitations may be overcome. This article will discuss the benefits of using two such languages, PHP and JavaScript, as well as provide source code for creating a basic demo application.

    Combining Scripting Languages

    PHP is a server-side scripting language, processed remotely before a page is rendered. As such, it has very limited access to client-side objects, and no real way of interacting with the client on its own once a page has been loaded. However, it has numerous strengths that make it a very practical and easily maintained choice for most of today’s dynamic website projects.

    JavaScript is a client-side language capable of interacting with the user in real time, even after a page has been rendered. Through the use of event handlers, Javascript may respond to a user’s button click, key stroke, menu selection, and so forth. Javascript is widely supported and continues to grow with each new release.

    By combining these two languages, many interesting things may be achieved. Perhaps one of the most common implementations is to dynamically generate and pre-populate a form using PHP, then validate the form’s various fields in real time through the use of JavaScript. For instance, this allows PHP to specify a field as being required and then rely on Javascript to enforce that requirement. This example is a rather simple one, but it is very useful.

    Most PHP and JavaScript combinations follow the basic forumla outlined below:

    Step 1: PHP functions retrieve and manipulate the data.

    Step 2: JavaScript functions validate user input and/or provide the user with helpful information.

    Although very useful, one drawback to the above process is the inability for PHP to further interact with the data in real time based on the user’s actions. In other words, JavaScript may respond to user input, but once the page has been rendered PHP cannot assist in manipulating or retrieving any additional information. This limitation lessons the user-friendliness of a system by requiring JavaScript to load or reload a page each time it needs PHP to process or generate information.

    In this article we will discuss an easily implemented way of getting around this problem by dynamically attaching PHP files to a page with the help of JavaScript. This will allow us to process information in real-time using not only JavaScript but PHP as well. Part 1 will discuss the basics, with a primary focus on attaching the external PHP files in a simple, example application. Part 2 will then expand our basic application and introduce a few additional concepts. By the end of the tutorial, you should have a firm understanding of how to effectively combine PHP and JavaScript in order to achieve a wide range of creative and unique results.

    More PHP Articles
    More By Brian Vaughn


       · Hi!When I tested these scripts I had problems with Opera and Safari.Safari...
       · With most people now using browsers that support XMLHTTP, at the risk of adding to...
       · You should not receive this problem.
       · Perhaps. Although I think this method is easier to work with, and (almost) as...
       · Unfortunately, I did not have ready access to a Mac while writing this article so I...
       · "rely on Javascript to enforce that requirement" - a fatal error
       · Amazing. This is great for quick and easy jobs. Ajax is probably a more stable...
       · Very, very cool a second technique for 'remote scripting' simple and works!Thanks;...
       · thanks for the kind words :)
       · thank you! :)
       · The same in Opera 8.5 on XP pro.
       · Hey - first of, this is a great tutorial. However I have in mind something a little...
       · thank you for the compliment.feel free to email me the details of your project...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT