![](/img/trans.png)
[英]How to disable form submit button using availity reactstrap validation
[英]How to disable form validation for some submit button?
在我的 jsp 表单页面中,我有两个提交按钮“保存”和“取消”。 当我点击这两个按钮时,它会验证表单。 我试图为取消按钮放置关键字“formnovalidate”。 但它不起作用。
在这里我提到了我的按钮代码:
<form id = "myForm" method="POST" onsubmit="return validateForm()" >
..........
<tr >
<td class="td_left"><input type="submit" value="save" onclick="form.action='${pageContext.servletContext.contextPath}/insert'"/></td>
<td class="td_right"><input type="submit" value="Cancel" onclick="form.action='${pageContext.servletContext.contextPath}/home'" formnovalidate /></td>
</tr>
................
</form>
验证:
function validateForm() {
var x = document.forms["myForm"]["spcrId"].value;
if (x == null || x == "") {
alert("SPCR ID must be filled out");
return false;
}
}
禁用“取消”按钮的表单验证的方法是什么?
我认为问题是因为您在表单的onsubmit
属性上进行了验证调用。 所以,这样的事情应该可以在没有onsubmit
属性的情况下工作:
<button name="action" class="btn btn-secondary" type="submit" value="Previous" formnovalidate="formnovalidate">Previous</button>
您可以使用:-
`<button type="button"></button>`
尝试这个:
<input type="submit" value="Cancel" onclick="this.form.setAttribute('novalidate', 'novalidate'); form.action='${pageContext.servletContext.contextPath}/home'" />
通过在单击事件上设置表单的novalidate
属性,您可以仅绕过该按钮的验证。
您必须使用而不是 type = "submit"
<input type="button" value="Cancel" />
或者你可以使用
<button type="cancel" onclick="window.location='http://your.com';return
false;">Cancel</button>
尝试这个
var myFormVar = document.myForm.FieldName.value;
if ((myFormVar == "") ) {
document.myForm.FieldName.value = '';
document.myForm.FieldName.focus();
alert ("alert here");
return;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.