我有一个具有各种选择输入选项的表单,我无法获得所需的指令。 谁能告诉我我做错了什么或错过了什么?我还包括我的页面顶部,其中html被声明,以防提供任何线索。 (我使用jquery和ajax发布表单)。谢谢。
这是一个bootply,但由于某种原因我的网页上没有
Jquery
<script>
$(document).ready(function(){
$("#submitButtonId").on("click",function(e){
$('#gauge').empty();
e.preventDefault();
//Post form
var formdata = $(this.form).serialize();
$.post('insert.php', formdata,
function(data){
//Reset Form
$('#myform')[0].reset();
fetchRowCount();
});
return false;
});
});
//Fetch data from server
function fetchRowCount() {
$.ajax({
url: 'server2.php',
dataType: "json",
success: function (data) {
$("#rows").html(data.rows);
$("#min").html(data.min);
$("#max").html(data.max);
$("#mean").html(data.total);
$("#last").html(data.last_entry);
//Show gage once json is receved from server
var gage = new JustGage({
id: "gauge",
value: data.total,
min: data.min,
max: data.max,
title: "Sample Data"
});
$("#gauge").fadeIn(slow);
}
});
}
</script>
The html form
<form class="form-inline" action="" id="myform" form="" method="post">
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="bill_cost"></label>
<div class="col-md-8">
<input id="bill_cost" name="bill_cost" type="text" placeholder="Bill Cost" class="form-control input-lg" required>
<select id="utility_type" name="utility_type" class="form-control input-lg" required/>
<option value="" >Energy Type</option>
<option value="Electric">Electric</option>
<option value="Gas">Gas</option>
<option value="Gas & Electric Combo">Gas & Electric Combo</option>
</select>
</div>
</div>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="submit1"></label>
<div class="col-md-4">
<button id="submitButtonId" name="submit1" class="btn btn-primary btn-xl">Submit</button>
</div>
</div>
</form>
答案 0 :(得分:2)
必需属性表示在提交表单之前必须填写输入类型。你不在这里使用表格标签,因此所需的属性毫无意义。
答案 1 :(得分:0)
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="bill_cost"></label>
<div class="col-md-8">
<form method="POST">
<input id="bill_cost" name="bill_cost" type="text" placeholder="Bill Cost" class="form-control input-lg" required>
</form>
</div>
</div>
必需属性仅适用于提交按钮
替换:
<button id="submitButtonId" name="submit1" class="btn btn-primary btn-xl">Submit</button>
用
<input type="submit" id="submitButtonId" name="submit1" class="btn btn-primary btn-xl" value="Submit">