Fill the textbox from the database as user types?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ogara
Forum Newbie
Posts: 1
Joined: Wed Feb 03, 2010 8:58 pm

Fill the textbox from the database as user types?

Post by ogara »

So,
I want to setup input text box on the page for user to type in their search. I do not want to wait for entire input since the user might misspell something in the long search. I need for my box to get that small nice box extension under input box which displays the search results from the database as user types input. I know how to work with database and php, so no need for detailed code. General guideline (objects that can do this) would be helpful as well.
Thank you
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Fill the textbox from the database as user types?

Post by califdon »

Since PHP is server-side script, there is no way for it to respond directly to what happens after it sends the page to the browser. That must be done by client-side script (Javascript) that detects the onChange event in the form and sends the contents-to-date in that control as an Ajax request to another PHP script that does the database lookup and sends the results back to the Javascript function, which must then re-populate the <select> and <option> elements of the form. If you are not familiar with Ajax, you will find lots of information online, just Google for it. The form element that produces a drop-down list is the <select> element. It is structured like this:

Code: Select all

<select name='[color=#FF0040]xxx[/color]'>
   <option value=1>First choice</option>
   <option value=2>Second choice</option>
   <option value=3>Another choice</option>
</select>
The words between the <option> and </option> tags are what are listed in the dropdown, and when one is selected, its value becomes the value of the the 'xxx' named <select> element, as a $_POST variable.
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: Fill the textbox from the database as user types?

Post by JNettles »

There are several prebaked PHP/Javascript scripts that can do this for you with minimal configuring - I used one just last week. Google is your friend.
Post Reply