I am using PHP and MySql. I have two listboxes on my form. One is a list of values I have entered (listbox1) the other is a list coming from the database (listbox2). What I want to do is only show data in listbox2 that corresponds to the item I select from listbox1.

example from listbox 1 is something like this:
Description: Acquisitions
Value: 05

from database:
Description: Purchases
Value: 05
Description: Sales
Value: 05

I have various items in the database that would correspond to the value shown in listbox 1 and I only want to show those items...How can I do this?

    I'm not sure if this is what you're asking:

    I want list box 2 to change options when I select something form list box 1.

    Is that it? If so, you can have PHP create the JavaScript to make this happen.

      That is correct. So how do I do this? I am trying to figure out how to get the selected variable out of Textbox1 but cannot get it out until after the form has been submitted. I don't know how to submit the form to itself without using the "submit" button either so any help with that would be greatly appreciated as well. Thanks.

        I don't remember correctly all the JavaScript syntax you will need. But you'll want to do this with client side JavaScript.

        Check out http://www.irt.org (if they're still around) and hit up their JavaScript FAQ then do Forms (I think).

        Basically, you'd want to do something like this:

        on list box 1 change, update list box 2 (use a function)

        function for list box 2 update:
        get selected value of list box 1
        clear list box 2
        use array associated with the value of list box 1
        parse array and rebuild list box 2

        This is based on the idea you have PHP build a JavaScript array of all the possible list box values and text. Then you have client side JavaScript parse this array (which is now a JavaScript array) and rebuild list box 2. Make sense?

          Write a Reply...