Solved

How can i filter a PHP listbox with javascript by userinput

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

790 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