0
我並不完全如何做到這一點,以及如何提出問題,所以我會盡我所能(PS:我是新的web開發人員,所以如果可以的話,請在你的答案中明確)。從選擇/選項標籤在PHP中提取值?
因此,我有一個列表名稱的下拉菜單,這些列表取自我的數據庫。在那個數據庫中,我有一個名字列的表格(那些呈現給下拉框的列表)以及這些名字的相關信息。現在,當用戶選擇其中一個名稱時,我希望相關信息出現在標籤下方。我也不能使用form.submit()方法,因爲我的submit按鈕已經被其他東西佔用了。
下面是代碼到該位:
<form name="name_choice" method="post" action="index.php">
<select name="names" onchange="form.some_method()">
<option value="NULL" selected="selected">--Select name--</option>
<?php
for ($i = 0; $i < $numrows; $i++) { //for all the columns, iterate and print out
$id_names = mysql_result($result, $i);
echo "<option value='".$id_names."'>".$id_names."</option>";
}
?>
</select>
</form>
所以上述位工作正常,但「some_method()」是我的問題,我不知道觸發以顯示文本什麼下拉框下面的DIV(代碼低於它):
<div class="information"> <!--if the name is chosen ONLY!-->
<?php
if($_POST['names'] == "NULL") {
echo '<p>Please select an option from the select box.</p>'; //this bit is for testing
}
else {
echo '<p>You have selected: <strong>', $_POST['names'], '</strong>.</p>';
//and then how to echo the relevant information?:(
}
?>
</div><!--end of possible info-->
非常感謝您的時間,對於錯誤的措辭感到抱歉,我盡力描述問題。 –