Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Dynamic Drop down in CGI

by dorward (Curate)
on Jun 09, 2009 at 14:21 UTC ( #769917=note: print w/ replies, xml ) Need Help??


in reply to Dynamic Drop down in CGI

Building with the principles of progressive enhancement, the first thing to do is to write it so it works without JavaScript.

There are two approaches you could take. Both will start with a select element containing the list of cities. Then you either…

  1. Have a simple text input in which the user can enter the data free form.
  2. Have a submit button and let the user go to a new page which gives them the next set of choices.

Then you can enhance with JavaScript.

If you went with the free form text input, remove it using JS.

Generate something to indicate that more options will be available once the first select has items picked. A disabled select element for instance.

When the first select has an item picked, populate the second one and stop it being disabled. You will need to get the data from somewhere. This could be included in the page at load time, or requested from the server (using an Ajax technique) on demand. The first option will be more responsible, but will have a heavier inital load. The decision should be based on the size of your database.

Getting the data into a form that is friendly to JavaScript is a good job for JSON::Any.

I'll leave out the specifics of writing the JavaScript to deal with that data, this is PerlMonks, after all.


Comment on Re: Dynamic Drop down in CGI

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://769917]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (15)
As of 2014-08-20 10:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (110 votes), past polls