Merhaba,
Onchange işlevine, XHR isteği ekleyebilirsiniz. pure javascript ile örnek;
<select id="selectNesnesi">
<option value="deger1">Değer 1</option>
<option value="deger2">Değer 2</option>
<option value="deger3">Değer 3</option>
</select>
document.addEventListener("DOMContentLoaded", function() {
const selectElement = document.getElementById("selectNesnesi");
selectElement.addEventListener("change", function() {
const selectedValue = selectElement.value;
// Veriyi PHP'ye gönder
sendDataToPHP(selectedValue);
});
});
function sendDataToPHP(value) {
fetch("post_handler.php", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: "selectedValue=" + encodeURIComponent(value),
})
.then(response => response.text())
.then(data => {
console.log(data);
})
.catch(error => {
console.error("Hata oluştu:", error);
});
}Bu kodda post_handler.php dosyasına seçilen değeri POST türünde gönderiyoruz. $_POST globali ile PHP tarafında alıp veritabanında değişim yapabilirsiniz.