where can i find a form script that updates the "city list" when state is chosen?
So, for example, if someone chooses "California" out of the State list (select box), the City list next to it gets updated with all of the cities in California.
Not sure if you can do it in pure JavaScript. Sounds more like a dynamic server language would be required (ColdFusion, PHP, ASP, etc.) and I say that because I assume you'd get city names from a database. From what I understand, pure JavaScript cannot access a database (if it can be done, someone please share that with me??)
So it would be a mix of dynamic server language and JavaScript.
Thanks, Wolfshade. This is a related question and I think I'd rather go this route rather than having the select box repopulate with the cities.
Here is what I'm envisioning:
The user selects a state, then in the 'Cities' box, he starts typing the name of his city. However, it autocompletes the name for him based on the state he chose. So if he chose California and started typing in "Los Angeles", it would autocomplete "Los Angeles" for him. Does that make sense? Is there a script out there that can do this? It would be amazing.
I've seen events like what you describe, but I've never viewed the script that does that. Even then, you'd still have to use a database - if you manually created a JavaScript array that would contain that data, it would A) be freakin' HUGE, and B) take forever to type it all in, assuming someone hasn't already made one. Heck, who knows.. someone may have already made something like that using an Access database. IDK.
Possibility ...
1. Create 50 external JS or text files containing the cities of each state.
2a. Load individual selected JS files depending on state selected
or
2b. Use ajax to load text files of the cities of each state selected from the DD.
Using auto complete might be possible, but it might get too complicated for you
if you are a beginner.
I pulled information of cities for each State from http://theus50.com and merged them into a single file to do a similar project. It runs about 1/2 megabyte.
I pulled information of cities for each State from http://theus50.com and merged them into a single file to do a similar project. It runs about 1/2 megabyte.
Where is the link to this single merged information file.
In .txt or .js format?
Mine is a .js file set up the way I wish to use it. It is much too large to post and hasn't been updated in over a year. The first few lines look like this:
Don't know if the following will fix anything, but it might help to define the problem...
In this part of the code try adding some alert messages to see what's going wrong.
Code:
var Items = StateCities[state]; // alert('Items:\n'+Items.join('\n'));
alert('Length: '+Items.length+'\n'+Items.join('\n'));
for (var x = 0; x < Items.length - 1; x++){
If that does not help to show the problem, try changing the assignment to:
Code:
// var Items = StateCities[state]; // alert('Items:\n'+Items.join('\n'));
var Items = StateCities[state].slice(0);
See if that changes anything ...
Also, does the post #9 work in the specified browser? Same error or not?
Join Date: May 2007
Posts: 3
#2: May 19 '07
re: null or not an object error in IE works perfectly in Firefox
found a solution. basically Internet Explorer is crappy and doesnt like the setAttribute property so had to change the onchange handler by directly changing the attrbute for the object like so.
object.onchange = function() {}
Incase anyone has a problem like this i hope the solution helps
Moj
I found another thing saying how the dom object is created in IE , i am trying to find that link...
Bookmarks