Cascading Dropdown In PHP - php

I have two dropdown list in my page i.e Location and Employee.
What I want to do is that I want to filter the employee according to the location.
That is ,,, When I select location Delhi than all the employees at delhi location are came into employee dropdown.
Is it possible in PHP????
Please help me out

That is not possible using just PHP unless you are okay with a page refresh in between. There are many ways to do this in JavaScript, have you tried using JavaScript?
EDIT: There might be some complex way using CSS3 selectors, but even if there is I would not advise doing it.

yes nothing is imposible. you can do it.. but you have to use scripting languages like ajax to accomplish that.. If you need more help please post your code....Yuo could find the answer here..
Populating second drop down based on selection of first with value from first database

Yes it's possible using php with ajax implementation.
Here's a good tutorial in which country, state, city example given. Hope this will help you.
http://roshanbh.com.np/2008/01/populate-triple-drop-down-list-change-options-value-from-database-using-ajax-and-php.html

Related

solution/alternative for dropdown menu with 100+ entries wanted

I have a html form that have one field that need to be filled with a value that match a selection from my database.
This is a typical form where you fill in contact information for a person, and then you assign a value based on a selection from the database. This selection will contain results between 10 an 200 hits..
A dropdown menu would fit to the layout and user interaction, but having 150 entries in a dropdown does not feel like a good solution.
Any suggestion for how to handle this in a nice and simple way? Simple is the keyword.
PHP and MySQL is used.
Any help is appreciated.
150 values in a select field is ok no problem, I have seen more and working good.
You can use a code like this to make it nicer and more accessible:
<select name="names" size="5" id="names">
<option>val1</option>
<option>val2</option>
<option>val3</option>
<option>val4</option>
...
<option>val150</option>
</select>
Select2 was a great solution.
Thanks to Mark Baker and Doink for pointing out that direction in the commments.
Having several values is not a problem itself, it is however not useable for the end user when it became hundreds of values.
Select2 offer a nice solution and filter out unwanted result in a handy way.
Easy to implement as well.

Changing dropdown list/check box options

I have 4 drop-down lists / group of checkboxes in I need that after making a selection in any one list the options available in the other 3 lists change accordingly...either are not available for selection or are not present in the list itself.
I'm coding using PHP & MYSQL
Could someone please help me with this. I'm new to PHP.
This can not be done with just PHP and MySQL. You need to use Javascript or jQuery. jQuery is the easiest to learn.
You can do it but very hard. You should use jQuery, it's easier than PHP.

Table Filtering with dropdown menu with jqGrid and php

I just wondering if i can create something similar to this but with javascript code cause i don't wanna buy the whole Jgrid php library.
I talk about the 4th column (drop down menu filter).
I have just create the first grid as they say here
Also i read some similar questions here but the most of them are based on ASP .net
If this can be achieved please give me some hints..
Thanks in advance.
What you need is just toolbar searching together with the common searching configuration. All the feature exists in the free open source version of jqGrid. Look at the demo. I hope it does what you need.

From PHP to jQuery?

So I've been struggling with finding a simple and efficient solution for the following problem. The solution I have now works, but since I'm working on this for the sake of learning ...
So, the case:
I have a PHP page which gets loads of persons from a DB, then sorts them and finally puts all persons
in a html list. What I'm after is a elegant solution to edit these persons by clicking on them from the list. I've found a jQuery pop-up solution that looks brilliant, but not so easy to use for beginners.
Since there are several persons I need to produce a different pop-up window depending
on which person is clicked. The problem is that the jQuery pop-up is based on the html being pre made, which is obviously hard since I don't know which person the user will click.
The best I've come up with so far is sending a GET -variable to the page with the person list, which then checks if there is a valid variable from GET and produces the HTML for the clicked person based on the id/variable. The problem with this is that I have to essentially run the same query twice; once to get all persons and once to get the clicked person. It isn't a big problem, it's more that since I'm new with jQuery I'm wondering if there is a simpler/better solution. I'm not really sure what jQuery can and can't do.
Thanks for any replies.
I'd start by asking why you don't ask the database to sort/ORDER the values before sending them back to your PHP page? It's well-suited for that sort of thing.
You could know which person was clicked if you added the database id to each element and passed that around. Have jQuery add it to the DOM element for each row in the HTML table.
kinda the standard way would be to pass the persons as JSON, and use the jquery templating system to build the forms. Of course this could be a bit daunting to a beginner, but its not that hard.

jQuery and PHP suggested answers

Hey guys, there is a form where the user select some of his friends and I'm curious on how I can implement a list that searches simultaneously while the user is typing a friend's name and when he selects the name the name is written in the text box(jQuery). And if the user wants to select more than one friend, when I'm inserting the names in the database, how can I separate the names that are written in one input field?
You should take a look at the jquery auto-complete plugin:
http://docs.jquery.com/Plugins/autocomplete
Also, you could separate the names using commas.
Are you looking to write your own plugin or would you like to use an existing one?
If you want something ready made, here are a few examples
if you want something extremely light, only 6kb packed, this one would be the best choice
Autosuggest jQuery Plugin
Older one but still good
Tokenizing Autocomplete
This what already asked here on this site.
Facebook style JQuery autocomplete plugin
The accepted answer cited this jQuery code.
https://github.com/loopj/jQuery-Tokenizing-Autocomplete-Plugin
http://jqueryui.com/demos/autocomplete/
Although think twice about including the whole jquery ui library for this one plugin
I've implemented this a couple of times, it is not that difficult to achieve decent results and the basic idea that I used was...
1) create an input box.
2) create a div positioned directly underneath the input box.
3) create a jquery keypress handler. if there are more than x characters typed, ajax request.
4) loop through the results, and if they exist, append result divs to the result box.
5) show the result box.
I can dig up some example code if you would like. Not sure what you are talking about with the select multiple, but you could keep a variable of selected, and change the color of the result div when it is clicked on, this way many results can be selected and then processed later.

Categories