/    Sign up×
Community /Pin to ProfileBookmark

Filtering after user selection.

Hi Guys,
I have a form containing 2 drop down lists which are connected to the database and obtain their values from database, in the database these to lists has a relationship too.
The problem is here that i want to filter the second list named field according to the value selected in the first list named faculty while user select it.
Thanks, waiting for your response.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmAug 13.2015 — If it has to be a real-time response to what the user chooses from the first select list, then it would have to be an ajax solution. Not sure if that is your intent since your English is a little confusing, but I think that is what you want.

So - write a js function to handle onchange event on the first drop-down and have it grab the new value and call a php script that returns the data to be used to build the second drop-down. Show us your code when you have it if you have any problems.
Copy linkTweet thisAlerts:
@esmatullaharifiauthorAug 14.2015 — here is my code, any solution you can provide
[CODE]
<div class="col-sm-6 col-lg-2">
<div class="form-group">
<select class="form-control" required onChange="" name="s_faculty">
<option disabled="disabled" selected="Selected">Select Faculty</option>
<?php
$result = mysql_query("SELECT DISTINCT faculty_name FROM faculty");
while($row = mysql_fetch_array($result))
{
$faculty = $row['faculty_name'];
echo "
<option>$faculty</option>
";
}
?>
</select>
</div>
</div>
<div class="col-sm-6 col-lg-2">
<div class="form-group">
<select class="form-control" name="s_department" required onChange="">
<option disabled="disabled" selected="Selected">Select Field</option>
<?php
$result = mysql_query("SELECT DISTINCT field_name FROM fields");
while($row = mysql_fetch_array($result))
{
$faculty = $row['field_name'];
echo "
<option>$faculty</option>
";
}
?>
</select>
</div>
</div>

[/CODE]
Copy linkTweet thisAlerts:
@ginerjmAug 14.2015 — I don't know what you want us to do with that sample. You build two dropdowns - one from faculty and one from fields(?). What do you want us to do? I see you included an onchange event call in one tag, but you don't call anything. What is that?

If you are hoping we are going to write your onchange handler and your ajax call and then the entire php script that your ajax code will call, not gonna happen.
Copy linkTweet thisAlerts:
@esmatullaharifiauthorAug 14.2015 — when user select any faculty from first list the second must be filtered the fields belongs to that faculty. I have provided primary key and foreign key for the relationship, just need to be filter the second list. ONCHANGE() is something extra.
Copy linkTweet thisAlerts:
@ginerjmAug 14.2015 — Apparently you can't read and understand what I last posted.

If you want help - write some code and when you have a problem with it, ask for help with it. Don't just tell us what you are dreaming about and hope we write it for you.
×

Success!

Help @esmatullaharifi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...