Hello, there is such a script and the problem happens that when you select the previous option, it does not replace values ​​here, but adds. Tried to make $("#selectf-"+ dataitemspl).empty()append(dispcity); so it deletes completely, that is, with value='0' is deleted too, but you need to leave it and delete only the others, and then it will be added accordingly.

 var dataitemspl = ++dataitems; for (var i = 0; i < infooption.length; i++) { var dispcity = dispcity +"<option value='"+ infooption[i] +"'>"+ infooption[i] +"</option>"; } $("#selectf-"+ dataitemspl).append(dispcity); <select id="selectf-2" name="selectf" data-item="2" data-name="city" style=""> <option value="0">Выберите город</option> <option value="Аликанте">Аликанте</option> <option value="Барселона">Барселона</option> <option value="Мадрид">Мадрид</option> <option value="Малага">Малага</option> </select> 

    1 answer 1

     var dataitemspl = ++dataitems; var dispcity = ""; for (var i = 0; i < infooption.length; i++) { dispcity = dispcity + "<option value='" + infooption[i] +"'>"+ infooption[i] + "</option>"; } var firstItem = $("#selectf-" + dataitemspl + " option[value='0']").clone(); $("#selectf-" + dataitemspl). empty(). append(firstItem). append(dispcity); 
    • If everything was so simple ... There are 5 such selects and there are different ones on each one - Chipa Chop
    • Okay, after if I’ll do it via data-items - Chipa Chop