I have a page with a form which contains a select box which gets populated from a mysql table through a php function when the page runs. I have added a 2nd list box above the previous one with hard-coded option values (it is located in the same form).
What I want to do is the following: When selecting a value in the hard-coded list box, this value should pass to the function that populates the other list box, i.e. this function should re-run but with the passed value from the hard-coded list box. (The reason I want to do this is that later I will modify the function so that it retrieves a subset of the previously retrieved group of values, i.e. values that are related to the selected value in the hard-coded list box, in other words do a filtering in the previous group of values based on the selected value in the hard-coded list box).
I don't want the form to be submitted with the onChange event on the hard-coded list box because the action of the form refers to a script that I don't want to run when selecting a value in the hard-coded list box, I just want the page to refresh with the filtered values output in the list box below.
I hope I made myself clear. Appreciate any help.
how to pass a value from a list box to a php function
Moderator: General Moderators
Re: how to pass a value from a list box to a php function
you can do this using JavaScript to access the DOM of the page. this will allow it to make changes to the page immediately, without visiting the server. you can read the list, filter the values, then recreate the list with only those filtered values. should work.
Re: how to pass a value from a list box to a php function
Is there any code example I could read to do your suggested method (I have very basic knowledge on Javascript, but enough to work things around if I found a code example that replicates my scenario as closely as possible).