Select cities by country

  • sciencemkt
  • sciencemkt's Avatar Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 95
  • Thank you received: 0

sciencemkt created the topic: Select cities by country

Hello,

I would like to know how you can do so that when you select a country, the cities of that country appear.

For example:
  • If the US is selected, the cities across the US should appear.
  • If you select Germany, you can see the cities of Germany.

Thank you.

Alejandro Cobo
Neuromarketing consultant

==============================================
Like us on Facebook:
www.facebook.com/AlejandroCobo.Neuromarketing
==============================================
Blog:
www.alejandrocobo.com
==============================================
#206654
  • Posts: 2222
  • Karma: 44
  • Thank you received: 279

marko.bosnjak replied the topic: Select cities by country

Hello,

I've created an example for you.
Create 2 select lists. The first should be named "country" and the second "city". The first has values:
1;Select Country;none
0;USA;usa
0;Germany;germany
The second list has only "0" inserted.
Now go to the "country" element > Advanced tab > Actionscript > Type > Custom > Actions > Change and use this code in the framework:
function ff_country_action(element, action)
{
    var city = ff_getElementByName('city');

    var usaArray = new Array(
        'New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix', 'Philadelphia',
        'San Antonio', 'San Diego', 'Dallas', 'San Jose', 'Austin', 'Denver',
        'Las Vegas', 'Seattle', 'Miami', 'Washington', 'Sacramento', 'Other'
    );
    var germanyArray = new Array(
        'Berlin', 'Frankfurt', 'München', 'Köln', 'Frankfurt am Main', 'Stuttgart',
        'Düsseldorf', 'Dortmund', 'Essen', 'Leipzig', 'Bremen', 'Other'
    );
    if (element.value == 'none') {
        // drop cities
        while (city.options.length > 0)
            city.options[city.options.length-1] = null;
    } else {
        // get the matching array
        var selectedArray = eval(element.value+'Array');

        // drop supernumerous option
        while (selectedArray.length < city.options.length-1)
            city.options[city.options.length-1] = null;

        // add the new options
        city.options[0] = new Option('Select City', 'none', true, true);
        for (var i=0; i < selectedArray.length; i++)
            city.options[i+1] =
                new Option(selectedArray[i], selectedArray[i]);
    }
}
Simply add more cities in the arrays between single quotes.
I will attach you the form. Install it and test it out.

Regards,
Marko

======================================
Support Crosstec and get ALL EXTENSIONS and professional support for just $5
Here!
======================================
Need to renew Pro Support?
Buy Here!
======================================
Satisfied?
Consider a Membership!
======================================
Follow us on Facebook!
#206694
Attachments:
The following user(s) said Thank You: sciencemkt
  • sciencemkt
  • sciencemkt's Avatar Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 95
  • Thank you received: 0

sciencemkt replied the topic: Select cities by country

It worked perfectly. :)

Thank you very much.

Alejandro Cobo
Neuromarketing consultant

==============================================
Like us on Facebook:
www.facebook.com/AlejandroCobo.Neuromarketing
==============================================
Blog:
www.alejandrocobo.com
==============================================
#206698
  • Posts: 2222
  • Karma: 44
  • Thank you received: 279

marko.bosnjak replied the topic: Select cities by country

Awesome!
I'm glad it's working for you.
Let us know if you have more questions.

Regards,
Marko

======================================
Support Crosstec and get ALL EXTENSIONS and professional support for just $5
Here!
======================================
Need to renew Pro Support?
Buy Here!
======================================
Satisfied?
Consider a Membership!
======================================
Follow us on Facebook!
#206699
  • Posts: 10
  • Thank you received: 0

1987Jan replied the topic: Select cities by country

Wie geht der Code mit einer dritten Auswahlliste? (Strassen)?
#239165
  • Posts: 2969
  • Karma: 100
  • Thank you received: 393

mihaela replied the topic: Select cities by country

Hello,

Similar to setting the possible cities for a specific country, where you write Actionscript in the city element, you have to write an Actionscript in the city select list to fill in the possible road options depending on which city is selected.

I hope this explanation helps.

Regards,

Mihaela
#239171
Moderators: ForumSupporttomeperica
Time to create page: 0.082 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here