Solved

How can i filter a PHP listbox with javascript by userinput

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 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

12 Experts available now in Live!

Get 1:1 Help Now