我是javascript和boostrap的初学者。我想要的是: 1.用户单击“提交”按钮。 2.使用entry_check()验证表单。 3.表单验证成功。使用用户输入值打开bootstrap MODAL。 MODAL将作为确认框,其中包含要提交或取消的用户值 4.单击MODAL POST表单中的“提交”按钮。
形式
<form role="form" id="ps_entry" name="ps_entry" method="post" action="/user/accounts/ps/add/">
Date<input name="date" id="date" class="form-control" autocomplete="off" />
Rate<input name="rate" id="rate" class="form-control" autocomplete="off" onkeypress="AmtCalc()" />
Box<input name="box" id="box" class="form-control" autocomplete="off" />
Amount<input name="amount" id="amount" class="form-control" readonly />
Payment Date<input name="pdate" id="pdate" class="form-control" autocomplete="off" />
Remarks<textarea name="remarks" id="remarks" class="form-control" autocomplete="off"></textarea></td>
entry_check()
function entry_check(){
var x = document.forms["ps_entry"]["date"].value;
if (x == null || x == "") {
alert("Please select Date");
return false;
}
var x = document.forms["ps_entry"]["rate"].value;
if (x == null || x == "") {
alert("Rate cannot be empty");
return false;
}
var x = document.forms["ps_entry"]["box"].value;
if (x == null || x == "") {
alert("No. of Box cannot be empty");
return false;
}
}
按钮
<input type="button" name="submitBtn" value="Submit" id="submitBtn" onclick="submitForm()" class="btn btn-default" />
onclick submit
$(document).ready(function(){
$('#submitBtn').click(function(){
var success = entry_check();
if (success) {
$('#confirm-submit').modal('show');
$('#dat').html($('#date').val());
$('#rat').html($('#rate').val());
$('#bo').html($('#box').val());
$('#amoun').html($('#amount').val());
$('#pdat').html($('#pdate').val());
$('#remark').html($('#remarks').val());
$('#submit').click(function(){
/* when the submit button in the modal is clicked, submit the form */
alert('submitting');
$('#ps_entry').submit();
});
}
});
});
答案 0 :(得分:0)
如果您想要一种更简洁的方式来验证表单,您可能需要查看jquery validate插件。
在提交时请执行以下操作...
var formValidationRules = {
rules: {
date: {
required: true
},
rate: {
required: true
},
box: {
required: true
},
(... more form fields)
}
};
$("#ps_entry").submit(function(){
$(this).validate(formValidationRules);
});