That code has been written, and I think it has even been shared on here in another thread, so you may want to try a search. I saw a thread recently where someone posted the code he was using to do cascading dropdowns in browser forms, and one of the Qdabra devs helped with it.