Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How can i filter a PHP listbox with javascript by userinput

Posted on 2009-05-13
2
Medium Priority
?
546 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

610 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