1 回答

TA貢獻(xiàn)1826條經(jīng)驗(yàn) 獲得超6個(gè)贊
添加 onChange 事件并將所選值傳遞給某個(gè)函數(shù),在該函數(shù)中使用該所選值設(shè)置隱藏字段?,F(xiàn)在您可以提交表單并可以接收您選擇的值。下面是解決方案。
$query = "SELECT on_programme, last_name, first_name, middle_name, id FROM constant_client WHERE on_programme=1";
$result = mysqli_query($conn, $query);
echo '<form action="selected_client.php" method="get">
<fieldset>';
echo '<p><label for="current_clients">Select Client by name: </label>
<select id="current_clients" name="current_clients" onChange="setId(this.value);">
<option value=""> -- Select Client -- </option>';
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo '<option value="'.$row['id'].'">'.ucwords($row['last_name']).', '.ucwords($row['first_name']).' '.ucwords($row['middle_name']).'</option>';
}
echo '</select>';
echo '<input type="submit" name="submit" value="Go!">
<input type="hidden" name="id" id="hidden_field" value="">';
echo '</fieldset></form>';
添加此腳本以在隱藏字段中設(shè)置值。
<script>
function setId(rowValue){
document.getElementById("hidden_field").value=rowValue;
}
</script>
- 1 回答
- 0 關(guān)注
- 130 瀏覽
添加回答
舉報(bào)