Forum Moderators: open

Message Too Old, No Replies

populating dropdown lists with javascript

         

BigBadBurrow

4:50 pm on May 28, 2005 (gmt 0)

10+ Year Member



Hi everyone,

I was wondering if anyone had any suggestions to my problem:

I have a site which has a drop down list displaying countries, when the user selects a country I use the "onchange" event to run some javascript code which then displays the "Counties/States" field with all the states for the selected country.

The method works fine, but due to the size of the file storing the states for the countries it takes way too long to download (it's about 4Mb) and obviously isn't a viable solution.

I was wondering, if you were in my siutation what method would you use to implement this?

Thanks,

BBB

RonPK

6:30 pm on May 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could post the user's selection to the server and have it return a new page with the appropiate data.

Or you could use the XMLHttpRequest object, which allows your script to communicate with the server and get the requested data without loading a new page. It's the same technique as used in for example Google Suggest.

Just out of curiousity: where did you get the data of all states(/provinces?) and counties in the world?

Bernard Marx

8:01 am on May 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We had a go at this the other day:

[webmasterworld.com...]