Page 1 of 1

Fill the textbox from the database as user types?

Posted: Wed Feb 03, 2010 9:04 pm
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

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

Posted: Wed Feb 03, 2010 9:22 pm
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.

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

Posted: Wed Feb 03, 2010 11:09 pm
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.