I have created a form which includes a select field where users can select a date for a delivery, the code below pulls information from a sql table which stores the available delivery dates. The problem i have is that im not sure how to display the selected date in a text box once they have made their selection (im sure this is simple code but my skills are basic!)
<select id="test" name="test">
<?php
$connect = mysql_connect("localhost","id294054_mike_butcher","delivery1");
$DB = mysql_select_db('id294054_delivery');
$test = mysql_query("SELECT date FROM test WHERE selected is null");
while ($row = mysql_fetch_array($test)){
echo '<option value="'. $row['value'] .'">'. $row['date'] .'</option>';
}?>
</select>
Here is working example
<select id="test" name="test" onchange="updateInput(this.value)">
<?php
$connect = mysql_connect("localhost","id294054_mike_butcher","delivery1");
$DB = mysql_select_db('id294054_delivery');
$test = mysql_query("SELECT date FROM test WHERE selected is null");
while ($row = mysql_fetch_array($test)){
echo '<option value="'. $row['value'] .'">'. $row['date'] .'</option>';
}?></select>
<input type="text" id="textInput" name="date" />
<script>
function updateInput(ish){
console.log(ish);
document.getElementById("textInput").value = ish;
}
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.