Created
November 12, 2021 11:57
-
-
Save barankaynak/b81eab88e8414accb12c27c7f314d1ae to your computer and use it in GitHub Desktop.
jquery sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> | |
<script> | |
$(document).ready( | |
function () { | |
$("#selectSehir").change(function() | |
{ | |
let selected = $(this).val(); | |
$("div").children().last().text(selected); | |
}); | |
$("#selectUlke").change(function () { | |
$("#selectSehir").empty().append($('<option>', { | |
value: "0", | |
text: "Şehir Seçiniz!" | |
})); | |
let selectedCountry = $(this).val(); | |
$("div span:first").text(selectedCountry); | |
$.post("https://countriesnow.space/api/v0.1/countries/cities", | |
{ | |
country: selectedCountry | |
}, | |
function (serviceData, status) { | |
for (const iterator of serviceData.data) { | |
$("#selectSehir").append($('<option>', { | |
value: iterator, | |
text: iterator | |
})); | |
} | |
} | |
); | |
}); | |
$.get("https://countriesnow.space/api/v0.1/countries/iso", | |
function (serviceData, status) { | |
for (const iterator of serviceData.data) { | |
$("#selectUlke").append($('<option>', { | |
value: iterator.name, | |
text: iterator.name | |
})); | |
} | |
}); | |
} | |
); | |
</script> | |
</head> | |
<body> | |
<select id="selectUlke"> | |
<option>Ülke Seçiniz</option> | |
</select> | |
<br> | |
<select id="selectSehir"> | |
<option>Şehir Seçiniz</option> | |
</select> | |
<div> | |
Seçilen ülke:<span></span> | |
Seçilen Şehir:<span></span> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment