There are a few examples of that functionality on javascript.internet.com ("The" resource for javascripts)
The data is stored in arrays, "all" you have to do is generate the content for those arrays, which is simply a copy of table-content, but seperated by whatever references them.
So you'r have an array of countries, then for every country you'd have one array for states, for each state you'd have arrays for cities.
Look at the javascript examples and you'll soon get the idea.