Solved

How can i filter a PHP listbox with javascript by userinput

Posted on 2009-05-13
2
527 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now