2014-11-08 23 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>

相关问题