PHP Classes

File: appz/type_ahead/type_ahead.php

Recommend this page to a friend!
  Classes of Guilherme Blanco   pAjax   appz/type_ahead/type_ahead.php   Download  
File: appz/type_ahead/type_ahead.php
Role: Application script
Content type: text/plain
Description: Type Ahead Script
Class: pAjax
Do RPC calls from the browser without page reloads
Author: By
Last change: Updated US States
Date: 18 years ago
Size: 2,362 bytes
 

Contents

Class file image Download
<?php

require_once "../../class.pAjax.php";

function
suggest($text) {
   
// It could be an SQL statement execution with a like condition, example:
    // SELECT stateName FROM USAStates WHERE stateName LIKE '{$text}%';
   
$database = array(
       
"Alabama", "Alaska", "Arizona", "Arkansas",
       
"California", "Colorado", "Connecticut",
       
"Delaware", "Florida", "Georgia", "Hawaii",
       
"Idaho", "Illinois", "Indiana", "Iowa",
       
"Kansas", "Kentucky", "Lousiana",
       
"Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota",
       
"Mississippi", "Missouri", "Montana",
       
"Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico",
       
"New York", "North Carolina", "North Dakota",
       
"Ohio", "Oklahoma", "Oregon",
       
"Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
       
"Tennessee", "Texas", "Utah", "Vermont", "Virginia",
       
"Washington", "West Virginia", "Wisconsin", "Wyoming"
   
);

   
$return = array();
    for (
$i = 0; $i < count($database); $i++) {
        if (
strtolower($text) == strtolower(substr($database[$i], 0, strlen($text))))
           
$return[] = $database[$i];
    }

    return
$return;
}


$AJAX = new pAjax;
$AJAX->handleRequest();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <head>
    <title>Auto Suggestion Type Ahead Example</title>
    <?php $AJAX->showJavaScript("../.."); ?>
<script type="text/javascript" src="autosuggestcontroller.js"></script>
    <script type="text/javascript" src="suggestionprovider.js"></script>
    <script type="text/javascript">
        window.onload = function () {
            var oTextBox = new AutoSuggestController(document.getElementById("TextBox1"), new SuggestionProvider());
        }
    </script>
  </head>

  <body>
    <h1>Type Ahead Suggestion</h1>
    <p>
      While you type anything on the input, it processes and autosuggest you by completing and selecting the word<br />
      The database of this example are the USA states. Try typing something like "New Mexico" and see what it appears while you type a char.
    </p>
    <input type="text" id="TextBox1" />
  </body>
</html>