Yassi
Yassi

Reputation: 2539

Javascript on Dropdown Select for Location

I'm new to Javascript and I need help.

I have my registration form with some sort of address / location field. By default the place is PHILIPPINES, so they need to select the regions in the philippines (drop down) then the towns / cities in that particular region they selected.

A region can have many towns / cities.

How can I make it that when they select on a dropdown menu a region then list of cities will appear to another dropdown which belongs to that particular region.

or is there any pre-made javascript out there for that?

Thanks!

Upvotes: 1

Views: 1926

Answers (1)

Selvaraj M A
Selvaraj M A

Reputation: 3136

You can listen for the change event in region select box and change the content of cities select box based on the selected value. Also note that this technique is using jQuery.

<select id="region"></select>
<select id="cities"></select>

$("#region").on('change', function () {
   $("#cities").html('<option>city1</option><option>city2</option>');
});

Upvotes: 1

Related Questions