?
Solved

How can i filter a PHP listbox with javascript by userinput

Posted on 2009-05-13
2
Medium Priority
?
556 Views
Last Modified: 2012-08-13
Howdy everyone.
Okey, so i got this php function retrieving information from a mysql table:
$sql = mysql_query("SELECT * FROM cast");
it returns a small table with columns CastId and Name.

And a search field:
echo "<input type=\"text\" name=\"searchCast\" value=\"Search here\">";

And a listbox to place the information.
echo "<select name=\"listbox\" size=\"10\" class=\"searchList\">";
      <option value=\"castId\">\"castName\"</option>';
echo "</select>";

So basically what i want is the listbox to view all the values in the box when the inputfield is empty (or showing the default value "Search here"). Then i want the listbox to filter its values based on input from the text from the inputfield.

Example info:
CastId             Name
0                     Arnold Schwartznegger
1                     Bruce Willis
2                     Julia Roberts
3                     Harrison Ford
4                     Christian Bale

If someone types "b" in the inputfield, it will filter the listbox (with onchange() maybe?) so that the Names not containing the character "b" will dissapear. In this example then only nr 1,2 and 4 will be displayed.

Of what i understand the most reasonable way to do this is to make the client do most of the work, with javascript. Should i somehow send a php-array to a javafunction, that returns the filtered array, and then print it to the listbox?

 If you having a hard time understand my problem, please specify it and i'll try explaining it further.

-eselpungen
0
Comment
Question by:eselpungen
2 Comments
 
LVL 7

Accepted Solution

by:
ycTIN earned 2000 total points
ID: 24381125
pure javascript enough , if is an small collection
http://www.barelyfitz.com/projects/filterlist/index.php/
0
 

Author Closing Comment

by:eselpungen
ID: 31581267
Thank you!!!!!!!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question