Home arrow PHP arrow PHP and JavaScript, Pooling Your Resources

PHP and JavaScript, Pooling Your Resources

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.

TABLE OF CONTENTS:
  1. PHP and JavaScript, Pooling Your Resources
  2. PHP Disguised as JavaScript?
  3. You Want More JavaScript?
  4. How Does This Work?
By: Brian Vaughn
Rating: starstarstarstarstar / 44
September 20, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: