HTML Tutorial

PHP vs Javascript

This page will explain the difference between Javascript, PHP and show a way to make PHP act more like Javascipt.

  1. With Javascript, a server sends HTML and Javascript to a computer.
  2. At the computer, a browser processes HTML and Javascript and displays the HTML on the screen. The user can see the Javascript by right clicking the page
  3. If the user triggers the Javascript it is proccesed by the browser
  1. A server processes the PHP and sends HTML and Javascript to a computer. The PHP is not sent and is not visible in the source code if the user right clicks.
  2. A browser processes the HTML and displays it.
  3. When the user submits a form the data is sent back to the server.
  4. The server processes the data with PHP and sends new HTML to the computer
  5. The browser processes the new HTML and reloads the page to show the revisions.

Now compare two forms that look the same and do the same thing, first with
Javascript then PHP:

Javascript -        PHP -
When you click the Javascript buttons the page changes but does not reload and the URL stays the same. When you click PHP button the page jumps because the form sends data to the server, the server sends HTML to the computer and the browser reloads the the page with the new HTML. The data is sent appended to the URL so the URL changes.

PHP with Iframes

The next form uses PHP but when you click it it acts like it uses Javascript. The URL doesn't change to reflect the data sent and the page doesn't jump from being reloaded. That is because it isn't actually on this page. It is on a different page and displayed on this page in an iframe.

<!-- setting height to 2em creates 
a scrollbar that needs to be hidden -->
<iframe src="example_01.php" 
        style="width:9em; height: 2em; 
               display: block; margin:auto;
               border:none"
        scrolling="no">
</iframe>