Well there where three options... until now ;)
A) Old School Server Madness: Yeah the standard to choose... in 2001. In this scenario the form is created with PHP, and when the selectbox of State change, you send a new almost identical page via GET or POST method with a fresh refill of Cities according to the state you send. This was the old way and i still see that methood going around in some pages. So why not use that?
Well fisrt is slow as hell and well.. AJAX anyone?, but the biggest reason why you should'nt work like that is because the server dont know if what you try to do when you send the POST/GET is getting new cities or sending the complete form filled, so you play with unnecesary hidden variables or check that all the fields are not empty,well just more work for such a simple thing
< ?php echo json_encode($array_of_cities) ?>
and that's it, you get a jsonized var that you can send to the client.He will do the rest. But wait, isnt this alot of unnecesary calls to the server? I mean that can be done faster if the server draw the first selects boxes and when we need a fresh supplies of cities we ajax it until fullfitness?. Yes but you are creating a new deja vu here, the client and the server are doing the same thing. So was wondering a few days ago a better way todo it, so here it is the:
D)Json Precharge Overdose: Well i guess there are alots of smartguys that have discover this method but , i never see any reference to this so here it is. Its a fusion from B and C.
Well in PHP you do something like this:
< ?php echo "var naked_data= eval('$array_of_cities') "?>