我正在尝试使用 JavaScript 验证文本字段。 return false
工作正常。但 return true
不起作用。
HTML
<form namme="frms" action="booking_management.php">
<input type="text" name="total" id="totald" value="" onkeyup="calbill()" class="input"/>
<input name="but" type="button" value="Send Bill" class="btn btn-primary" onClick="bill()" />
</form>
JavaScript
function bill() {
if (Checktot()) {
document.forms["frms"].submit();
}
}
function Checktot() {
var tot = document.getElementById("totald").value;
if (tot == "no") {
document.getElementById("totald").style.borderColor = "#ED291F";
alert("Please try again");
return false;
}
return true;
}
最佳答案
您收到错误:
Uncaught TypeError: Cannot read property 'submit' of undefined
document.forms["frms"].submit();
<小时/>
你可以使用这个:
document.forms[0].submit()
关于javascript - 如何使用 javascript 验证文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28870606/