v2.5.2
Giriş yap

Php'de Select-Option ile Id Çekme

yazilimyolcusu
2,011 defa görüntülendi

Benim sorunum şu:
Select Option ile "Konya" yı seçtiğimde "Konya" nın id'si gelsin istiyorum. "Ankara" yı seçtiğimde "Ankara" nın id'si gelsin istiyorum. En son Ankarayı ekledim id si 37. Konya yı ekledim 36. id ile. Galiba javascript ile yapılabiliyor ama ben beceremedim. Yardım edebilir misiniz?


<html>
    <h4><u> Albüme Resim Yükle </u></h4>
	<form action="a.php" method="post" enctype="multipart/form-data">
	
	<label style="font-size:16px;" for="albumsec">Albüm Seç</label>
	<select style="margin-left:10px;" id="album" name="albumsec" onchange="deger();">
	
	<?php
	$resimalbumusorgulistesi=$db->prepare("SELECT * FROM resimalbumu");
	$resimalbumusorgulistesi->execute(array());
	$resimalbumusorgusu=$resimalbumusorgulistesi->fetchAll(PDO::FETCH_ASSOC);
	foreach($resimalbumusorgusu as $resimalbumu) {
	?>
	
	<option value="<?php echo $resimalbumu['resimalbumu_id']; ?>"><?php echo $resimalbumu['resimalbumu_adi']; ?></option>
	
	<?php } ?>
	</select>
	<br>
	<input type="text" name="sirasi" style="text-align:center;">
	<br><br>

	<input type="text" name="idsi" style="text-align:center;" id="id" value="<?php echo $resimalbumu['resimalbumu_id']; ?>">
	<br><br>
	<input type="file" name="files[]" value="Resim Yükle" />
	<br>
	<button style="margin-top:7px; width:90px; height:30px; background-color:green; color:#fff; border-radius:7px;" name="submit">Gönder</button>
	</form>
</html>
onlywhatchess
1168 gün önce
<input type="text" name="idsi" style="text-align:center;" id="id" value="<?php echo $resimalbumu['resimalbumu_id']; ?>">
<!--  Bu kısım foreach dışında kalmış, çalışmıyordur. -->
var album = document.querySelector('#album'); // Select
var id = document.querySelector('#id'); // Input
album.addEventListener('change', () => {
    id.value = album.value;
});