Using Ajax Agent and PHP for Auto-Complete
Written By: Jay
- 15 Jun 2006 -
Description: In this HOWTO I will explain how to use AjaxAgent and PHP to create an Ajax Auto-Complete box with a drill-down list of data. The UI is very simple. It consists of a TextBox to enter an Artists' Name, a selectbox to display the Albums and an unordered list to display the songs on an album.
Part 1: Auto Complete
Start by creating a new PHP page and placing the agent.php (Ajax Agent) file in the same directory. Open your new PHP page in an editor and start hacking away.
First create the HTML Form controls we will be using:
- txtArtists = TextBox to type the ArtistName in.
- matches = A SelectBox with an onclick event which will be used to send the ArtistName to the AlbumSearch method we will be creating.
- txtArtistID = Hidden to hold the selected ArtistName (js cannot see the select box because it is hidden?)
- htmlOutput = An empty DIV when we will be creating a list of Albums
- htmlOutputTracks = An empty DIV when we will be creating a list of Tracks
HTML: