[英]Second input box in form doesn't work second time
I have this form:我有这个表格:
<form id="addChore" method="post" action="allocate.php">
<label>Name of new chore:</label>
<input type="text" id = "choreName" name="choreName">
<p></p>
<label>Description:</label>
<input type="text" id="description" name="description">
<p></p>
<label>Frequency:</label>
<select id="frequency" name="frequency">
...
</select>
<input type="submit" value="Submit">
</form>
and this jQuery还有这个 jQuery
$(document).ready(function(){
$("#addChore").on('submit',function(e){
e.preventDefault();
$("#error").empty();
var name = $("#choreName").val();
console.log(name);
var description = $("#description").val();
console.log(description);
var frequency = $("#frequency").val();
console.log(frequency);
var message=("Please fill all fields");
// $('#addChore')[0].reset();
if (!name || !description){
$("#error").append("<p>"+message+"</p>");
return false;
}
else{...}
but when I try and use the form a second time, description is empty in the log, while name and frequency accept a new input.但是当我第二次尝试使用该表单时,日志中的描述为空,而名称和频率接受新的输入。 I have tried resets and.val("") but nothing seems to change this.我已经尝试过 resets and.val("") 但似乎没有任何改变。 Any help?有什么帮助吗? :/ :/
Turns out I had another element with the same id, but defined in php in a separate script原来我有另一个具有相同 id 的元素,但在 php 的单独脚本中定义
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.