I have 2 tables, Provinces and Districts. I would like to populate a select field with options as District names based on which Province is chosen in another select. The Districts table has a ProvinceID field to reference which Province it belongs to. I know this is doable, I just can’t figure it out. I also want to create and update the new Districts select without refreshing the page.
UPDATE: I’m writing it in PHP and MySQL, using jQuery as sparingly as possible.
I actually figured this out on my own using jQuery and post. On the primary select, I added onchange=”getDistricts()” and used this for that function:
And then in handler.php, I have a case that catches the mode, and runs the following code:
I’m not a fan of this solution, and would really like something better, but it does what I need it to do for the moment. I hope this can help someone else out.