Page 1 of 1
Fill a list box based on drop down
Posted: Tue Mar 30, 2004 12:29 pm
by dougp25
I have a form attached to a database of students, Grades 5-8.
I have a dropdown list that has the grades teachers can choose from. When they choose, for example, 7, I would like thelist box below to fill with the 7th grade students. Coming from VBA (ugh) there was an "after update" event that would run when you changed the dropdown. I don't mind if they have to click a button that says "GO" after they pick a grade, but how do I fill that list box?
Thanks.
Posted: Tue Mar 30, 2004 12:50 pm
by amithn12
Once u select a grade from the drop down box, say 7 u can do either of 2 things , one u can reload the same page but u r passing parameters to the page when reloading, which u can get by POST method and query u r database based on the grade and and get the students belonging to that grade and fill it in the List box.
or
ucan give the GO button and do the same thing.
For Example:
when u first come to the page :
have a flag and a grade variable.
$flag,$grade
$flag = $_POST['flag'];
$grade = $_POST['grade'];
Check if the flag is 0 which is the initial value u will be passing from the last page.then do not fill the list box with Student Names.
Once if they select a Grade and click GO u make a hidden field and give the value as one for flag
and when u submit the form u will have the value of flag as 1 then do the required database qeries from the
selected drop down list. the value of the dropdown list will be posted so give appropriate values so that u can
search the databse with the values and fill the list box that is it.
for ex:
if ($flag == 0)
{
do not fill list box
}
if ($flag ==1)
{
search the databse with the Grade value and put it int he list box
}
Posted: Tue Mar 30, 2004 12:59 pm
by magicrobotmonkey
Or you can do it with javascript. I'm not entirely sure how, I'm not a javascript expert but it would be a function. In the textbox you'll have
onChange="update()"
and update will be
if(form.textbox.value==7)
form.listbox.value = "list \n of \n Student \n names
where the names are culled from your dbase. When you build the page uyou can populate the javascript from the php. I'm not sure exactly how the javasript goes, you'll have to look into it. But thats how I would do it.
Posted: Tue Mar 30, 2004 3:26 pm
by pickle
Ya, in order to be as responsive to the user as possible, I'd suggest doing it how ~magicrobotmonkey suggests.