1. Computing & Technology

Using PHP and Javascript instead of CGI

From , former About.com Guide

Passing Form Data With Javascript

To pass form data using Javascript, use the function 'submit()'. The syntax of submit is 'submit(<form_data>)'. So, in HTML, one writes as follows:

 <form action="search.php" method="post"> 
 <h5> Search <br> 
 <input type='text' name='word' size='20' onChange="submit(word)"><br> 
 </h5> 
 </form> 
 

This will allow the user to submit the form by simply pressing 'Enter' instead of clicking on 'Submit'. As you can tell, the form data will be passed to a PHP script called 'search.php' which resides in the same directory. Putting a script in the same directory may sound like a security issue at first, but PHP is designed for discretion and will return an empty HTML document instead of code when accessed directly.

To be fair, one could use a simple HTML form here, but the Javascript allows one to offer the visitor to your website a better experience.

©2012 About.com. All rights reserved.

A part of The New York Times Company.