I have a selectbox where i can choose my clients and each client could have 1 or more sites, so when you change your client selection the sites selectbox should also change, but teh main problem is that i can't fill the sites selectbox with options.
I thought it should be the best way to return an array or something.
I took a little bit of time but wrote something that might work and simple. Also if you're using AJAX you really don't need to have form tags. You can create form with dives and use a JQuery function to fire AJAX to send data to the database.
Main PHP to populate your first drop down.
This PHP will receive the AJAX post variable and echo out the options which will populate the second drop down.
This code is for your AJAX which will send the your set kalntId to the above second PHP onChange of your first drop down. The ajax will send the selected clients ID to the PHP so you can sort out the sites only for that client. Then will capture the echoed output and insert those as option in to the second drop down.
Hope this helps you or any other.
P.S: I'm not a big mysqli_* user if there's any errors in my code please let know. Also I used prepared statement where the second PHP binds the value which is much safer and prevents SQL injection.
Try adding something like this to your ajax success:
Essentially creating an array with the information you want to be displayed, is a good idea. But you should try to also work with a value on the select. So when you select an an option the system will know it's id. ->
dropdown.options[dropdown.options.length] = new Option(element, 'ID of Array Element', false, false);