2014-07-15 123 views
0

我有這個選擇框,如果我選擇其他文本框將顯示和問題是我放在那裏的數據只有獲得值「其他」,即使我把文本在文本框中唯一的價值它獲得是「其他」,所以你建議我這樣做。 我使用$ _POST ['talent']來獲得價值。獲取選擇的值php

Talent: 
    <select name="talent" onchange="if(this.value=='other') { this.form['other'].style.visibility='visible' }else  { this.form['other'].style.visibility='hidden' };" required/> 
    <option value="Dancing">Dancing</option> 
    <option value="Singing">Singing</option> 
    <option value="other">Other</option> 
    <input type="text" name="other" style="visibility:hidden;" /> 
    </select> 
+0

'$ _POST ['talent']'會給你所選擇的選項的值,而不是文本輸入的值。 –

+0

添加jQuery並添加一個onChange偵聽器,顯示您發佈數據的PHP位置。如果($ _ POST ['talent'] =='other'){//然後從$ _POST ['other']獲得值} –

+0

這就是我之後的 我想獲得在文本框中輸入的值,如果我選擇其他。 – user3840545

回答

3

$_POST['talent']只會返回select元素的值。如果該值爲「其他」,則表示用戶已選擇該選項。在這種情況下,您需要$_POST['other']以獲取它們鍵入的值。

$talent = $_POST['talent']; 
if ($talent === 'other') 
    $talent = $_POST['other']; 
0

您需要使用$_POST['other']才能獲取文本框的內容。另外,您需要將文本框放在</select>之後。