我想做一個下拉菜單有幾個選擇,並選擇「其他」,這將允許用戶輸入自己的價值。HTML,Javascript,PHP的 - 選擇菜單+其他輸入框
我已經這樣做了,但是那得到的已保存的唯一的價值是從文本輸入框中的值,而如果我不選擇其他,而是從菜單中選擇值爲空的值。
<?php $val = $_POST["Room"]; ?>
// the value here is blank when choosing the drop down menu options.
Here's我的代碼(相關部分):
JavaScript函數:
<script type="text/javascript">
function checkSelectedValue(val){
var element=document.getElementById('roomnumber');
if(val=='other'){
element.style.display='block';}
else{
element.style.display='none';}
}
</script>
<p><label>Room number:<br>
<select name="Room" size=4 onChange='checkSelectedValue(this.value);'>
<option value="1/201" selected="selected">1/201</option>
<option value="2/201">2/201</option>
<option value="3/201">3/201</option>
<option value="other">Other</option>
</label></select>
<input type="text" name="Room" id="roomnumber" style='display:none;'/> </p>
而PHP:
$val6 = $_POST["Room"];
// I continue to write values into a .csv file and such...
爲什麼它只是拿起那得到由輸入框時,如果選擇其他寫入的值?
在此先感謝!