我有这段代码,但是,它没有验证表单...
请注意,这不是整个页面,只是一小段。该代码应验证不同的标签,但我不想使用html属性。它需要用JavaScript完成...
我的编码哪里出错了?
django_filters.ChoiceFilter
HTML:
//To disable the radio buttons
function disableStuffNo(){
//random comment to post
document.getElementById("tele").disabled = false;
document.getElementById("whatsapp").disabled = false;
//random comment to post
document.getElementById("call").disabled = false;
document.getElementById("email").disabled = false;
}
function disableStuffYes(){
document.getElementById("tele").disabled = true;
//random comment to post
document.getElementById("whatsapp").disabled = true;
document.getElementById("call").disabled = true;
//random comment to post
document.getElementById("email").disabled = true;
}
//To validate the form
function validateForm() {
var a = document.forms["Order"]["Fname"].value;
var b = document.forms["Order"]["Lname"].value;
var c = document.forms["Order"]["topic"].value;
if (a == ""||b == ""||c == "") {
alert("Everything must be filled out");
return false;
}
答案 0 :(得分:0)
对于我来说,它实际上没有任何问题。我只要复制/粘贴代码即可。 我的建议是:
1)尝试在关闭body标签之前将javascript代码直接包含在html中
import numpy as np
from scipy.io.wavfile import write
noise = np.random.uniform(-1,1,100000)
write('noise.wav', len(data), noise)
2)如果有效,请检查指向您的外部javascript文件的链接是否正确。您可以通过检查Element并检查控制台是否存在404错误(“找不到file.js”)来做到这一点。
因为它对我有用,所以我真的不认为这是代码错误,可能会变成选项2。
答案 1 :(得分:-1)
这应该可以帮助您:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
Firstname <input type="text" id="fname" maxlength="40"><br>
Lastname <input type="text" id="lname" maxlength="40"><br>
Topic <input type="text" id="topic" maxlength="50"><br>
<button id="testbutton">Check form</button>
<script>
var isFormValid = function() {
var a = document.getElementById("fname").value;
var b = document.getElementById("lname").value;
var c = document.getElementById("topic").value;
if (a == "" || b == "" || c == "") {
alert("Something is missing");
return false;
}
return true;
};
var button = document.getElementById("testbutton");
button.addEventListener("click", function() {
if (isFormValid()) {
console.log("Form is valid");
}
});
</script>
</body>
</html>