Python

  1. Home
  2. Computing & Technology
  3. Python

Using PHP and Javascript instead of CGI

From Al Lukaszewski, for About.com

5 of 9

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.

Explore Python

About.com Special Features

Python

  1. Home
  2. Computing & Technology
  3. Python
  4. Web Development
  5. PHP and Javascript for CGI - Passing Form Data With Javascript

©2009 About.com, a part of The New York Times Company.

All rights reserved.