2014-11-08 58 views
0

我在我的HTML代碼中具有以下表單。無法在更改選項後不刷新表單值

當我忘記填寫姓, 表格會告訴我一個「泡泡消息」 You have to fill in the surname,然後我 將填補姓,按提交按鈕和值提交。

當我忘了默認選項從<select>改變形式將顯示 我一個「泡泡消息」 You have to choose something,那麼我會選擇另一種選擇, 按提交按鈕,但值未提交。我總是要刷新 的頁面。你知道問題出在哪裏以及如何在不刷新的情況下實現它?

<form action="add" method="post"> 
    ... 
    <select id="choice" name="choice" 
    required oninvalid="setCustomValidity('You have to choose something')" 
    oninput="setCustomValidity('')"> 
    <option value="" selected="selected"></option> 
    <option value="first">first</option> 
    <option value="second">second</option> 
    </select> 
    ... 
    <input type="text" name="surname" id="surname" value="" 
     required oninvalid="setCustomValidity('You have to fill in the surname')" 
     oninput="setCustomValidity('')"> 
    ... 
</form> 
+0

在我的回答在下面的提交值沒有問題,這意味着您需要提供完整的代碼示例。 – Timmerz 2014-11-08 18:24:15

+0

may [this](http://stackoverflow.com/questions/26658784/php-dropdown-option-selected/26659241#26659241)幫助你? – 2014-11-08 18:25:44

回答

0

有一個與表單數據提交,你將從這個的jsfiddle例子看看有沒有問題:正如我所說

http://jsfiddle.net/vbnh1a4y/

post example

<form action="/echo/html" method="post"> 
 
    <select id="choice" name="choice"> 
 
    <option value="" selected="selected"></option> 
 
    <option value="first">first</option> 
 
    <option value="second">second</option> 
 
    </select> 
 
    <input type="text" name="surname" id="surname" value="" /> 
 
    <input type='submit' /> 
 
</form>

相關問題