Either grab all the potentially needed data and load it into one or more JavaScript arrays so that you can do an all-JavaScript solution, or else use an AJAX implementation (combining JS with PHP) to grab data from the server as needed. The AJAX solution requires less data to be downloaded with the initial page request, but will be slower to respond when you change the first select, since a round-trip request has to/from the server before the other element can be updated.