A
A
Alexander2015-10-15 15:43:41
JavaScript
Alexander, 2015-10-15 15:43:41

How to sort select from another select?

Good afternoon, there are 2 selecta:

1:
<option value="343">Адыгея</option>
<option value="344">Алтайский край</option>
<option value="345">Амурская область</option>
2:
<option value="Алтайский край">Алейск</option>
<option value="Пермский край">Александровск</option>
<option value="Алтайский край">Барнаул</option>
<option value="Алтайский край">Белокуриха</option>

how to make it so that when choosing in the 1st list, for example, the Altai Territory, only the cities of the Altai Territory are displayed in the second list?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IceJOKER, 2015-10-15
@IceJOKER

after selecting in the first field, send the id of the selected element using ajax to the backend, from there you return the elements for the second select in response.
if you want purely on the frontend, then when outputting, set the class to something like class="ragion_{REGION_ID}" and then you can remove unnecessary regions
, in general, there are many different options for solving this problem

D
Denis Ineshin, 2015-10-15
@IonDen

You must create in advance on the server or on the client a tree structure of regions and cities in them. Then everything will be easy to sort.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question