Application Design: Dynamically Change State and City Drop-Down Boxes with DHTML

xiaoxiao2021-03-05  52

State and city drop-down boxes are a perfect opportunity to use JavaScript. Each state has a limited number of corresponding cities, so why not make the city drop-down box update itself every time a new state is chosen.

The only problem with writing a strictly JavaScript approach is that you would have to write over 30,000 lines of code to match each and every single state / city option. While this may be fun for some, most of us have better things to do, like Perhaps Code The Rest of the Form.

.

Now if only we could get the coldfusion and javascript to talk ...

The code, version 1: Joint ColdFusion / JavaScript dynamic Web pageThe code to generate the page is very simple It is comprised of about 50 lines which are broken into three sections:. The ColdFusion queries, the form with drop-downs, and the JavaScript Code (Enhanced with a bit of foldfusion) to facilitate the switching.

The Queriesthe First Section of Code Is Comprised of Two Queries

Listing a). The first query ooes to get every (s) in the database to get evening distinct city-state combination. The second query is merely a subset of data from the first query to find all the distinct stats.

THE FORM WITH DOWNSNEXT, WE Take a Look at The Form

Listing b). This Form Is A Simple Form Comprised of Just The Two Drop-Down Boxes in Questions: One for State and The Other for City.

Note That you utilize the

Allstates Query Decland in Listing a to create the

CopyRight © 2020 All Rights Reserved
Processed: 0.055, SQL: 9