Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Change state form based on country selected

New Here ,
Jul 28, 2008 Jul 28, 2008
I use DW CS3 with CF8.
I have a country form on a shipping page. If the country is USA, I want to make the state form a select box that outputs a query named "qryStateList" that list all the states in the USA. If the country is NOT USA, I want the state form to be a text box where the user can type in the value for the state. Can anybody help me with this javascript or can show me a discussion on this already?
TOPICS
Advanced techniques
633
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 28, 2008 Jul 28, 2008
Hey Mark,
This is something that can be done with Javascript:
http://javascript.internet.com/forms/country-state-drop-down.html
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 28, 2008 Jul 28, 2008
I tried that code before I left my post. It doesn't work for me, but maybe let me play with it and see if I did something wrong.

One of the things I don't like about that code is that it doesn't use the output of a query to get the state and country list, which is what I'd prefer.

Any other links or ideas would be much appreciated!!!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 28, 2008 Jul 28, 2008
The first thing I would do is add as much data to my db as possible. You already have the American states. Add the Canadian provinces and the equivalent records for every other country you are interested in. For countries without states, add a record to that table stating so.

Then you can use related selects, if you know how.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 28, 2008 Jul 28, 2008
I already have the data in the db...I don't know how to output it using JS.

I also don't know why that JS in the link that Julio gave me doesn't work on a test page. The demo works, but I copy the code in all the right places and it doesn't.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 28, 2008 Jul 28, 2008
If you already have the data in your db, why are you offering the user a text box? You think they are always going to spell Saskatchewan correctly?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 28, 2008 Jul 28, 2008
Mark, I looked at the code and realized they should have given better instructions. The top part (with all the functions and javascript code) should be on a separate file, copy that code and save is in a file, you can call it something like statefunction.js, then in the HEAD section of your test file you would include the .js file. Then the form they give you should work. Once you get it to work and know how the code works you can try putting all the Javascript code into the HEAD of your document, then use CFOUTPUT to output your own list of countries and states/provinces, using the same format they have for countries and states.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 28, 2008 Jul 28, 2008
Julio,
I thought the instructions were just fine. I made the seperate .js file. I put the form on a test page by itself with a link to the js, but no luck yet.

"then use CFOUTPUT to output your own list of countries and states/provinces, using the same format they have for countries and states."
Are you saying I can use a cfoutput in my js file for this list assuming my field values are the same?

"
If you already have the data in your db, why are you offering the user a text box? You think they are always going to spell Saskatchewan correctly?"
I have a list of all the countries and all the states, but not all the states/provinces in all the countries. For the ones I don't have, I want them to type the value.

I will keep playing with this JS, but I would think that there is another example out there that is better.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 28, 2008 Jul 28, 2008
I got that script to work...I didn't realize until i tried to paste the code itself into my head tag that I had script tags in the js file...er..uh..oops.

Now I will try to do the cfoutput thing Julio says to try.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 29, 2008 Jul 29, 2008
LATEST
You can't use CFOUTPUT on the JS file, but you can copy all the Javascript code into the HEAD of the document and THEN you can use CFOUTPUT to list your countries and states/provinces.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources