Merhaba, İyi Forumlar,
Bu şekilde il ve ilçe seçimi yapan bir kodum mevcut, İl ve ilçeler json dosyası üzerinden çekiliyor. İstediğim şey varsayılan olarak istanbul değerinin gelmesi.
$.getJSON("https://raw.githubusercontent.com/Kreawich/Kreawich/main/tr-il.json", function(sonuc){
$("#il").html("<option>Seçiniz</option>");
$.each(sonuc, function(index, value){
var row="";
row +='<option value="'+value.il_id+'">'+value.il_adi+'</option>';
$("#il").append(row);
});
});
$("#il").on("change", function(){
var il=$(this).val();
$("#ilce").html("");
$.getJSON("https://raw.githubusercontent.com/umut79/dinamik-ililce-json/master/tr-ilce.json", function(sonuc){
$("#ilce").html("<option>Seçiniz</option>");
$.each(sonuc, function(index, value){
var row="";
if(value.il_id==il) {
row +='<option value="'+value.ilce_id+'">'+value.ilce_adi+'</option>';
$("#ilce").append(row);
}
});
});
});Bunun için stackoverflow'da araştırma yaparken şöyle bir şeye denk geldim,
$("select[name='language']").find("option").each(function() { // Find all 'options' in your select
if($(this).val() == json[0].language_id) { // Compare the value of the 'option' with your JSON-value
$(this).attr("selected", "selected"); // If this matches, set the selected="selected" attribute for the <option>
}
});Select inputunda varsayılan değerin İstanbul olarak gelmesini nasıl sağlayabilirim?