Been looking for a few days for the answer and even tho I think this should be simple, I just can't seem to make it work.
First I populate a "select" with values from my database with a while loop.
<select class="admin-content-select" name="sale">
<?php try {
$stmt = $db->prepare('SELECT saleID, saleKal, saleNr FROM wcms_sale');
$stmt->execute(array(':saleKal' => $row['saleKal']));
while($sale = $stmt->fetch()){
echo '<option value="'.$sale['saleKal'].'">'.$sale['saleKal'].'</option>';
}
}catch(PDOException $e) {
echo $e->getMessage();
}
?>
</select>
then I have an input field which I need to get populated with a value based on what is selected. The values are on the same row in the db so my initial thought was that it would be easy to say: "when X row is selected, echo Y" but since it's a while loop it will simply echo a lot of input fields.
Any work arounds or am I totally in the wrong here with the while loop?
Hope I explained this right and thanks beforehand for any answer :)
Answer:
<select id="saleName" class="admin-content-select" onchange="changeFunc()">
<option value="'.$sale['saleNr'].'">'.$sale['saleKal'].'</option>';
Then added a function as suggested:
function changeFunc(){
var x = document.getElementById("selectID").value;
document.getElementById("inputID").value = x;
}
Thanks for all the answers!
wcms_sale?saleKalvalue when click on the respectiveselectvalue?