【发布时间】:2016-06-30 09:56:09
【问题描述】:
我想验证此表单。其中第一个字段获得的分数不应超过 1100 或小于 1,第二个字段的总分应为 1100 .. 第三个和第四个字段将与前两个字段相同,但 ID 不同,最后一个字段的分数应不大于 200 或小于 1.. 除非输入完全正确,否则表单不应继续
function myFunction() {
var x, text, y, z;
// Get the value of the input field with id="numb"
x = document.getElementById("mfsc").value;
y = document.getElementById("matric").value;
z = document.getElementById("per").value;
// If x is Not a Number or less than one or greater than 10
if (isNaN(x) || x < 0 || x > 1100) {
alert("marks should be less then 1100");
}
if (isNaN(y) || y < 0 || y > 1100) {
alert("Matric Marks should be less then 1100");
}
if (isNaN(z) || z < 0 || z > 200) {
alert("NET Marks should not be more then 200");
}
}
<form action="merit-nust.php" method="Post" name="Form1" onsubmit="return validateForm()">
<div class="style1"> Enter Your marks in FSc</div>
<div align="left">
<input type="text" required style="width: 160px; float: left; margin-right: 1%;" size="20" placeholder="Obtained Marks in FSc Part-I" id="mfsc" class="TextBox form-control">
<input type="text" required class="TextBox form-control" placeholder="Total Marks in FSc Part-I" name="totalfsc" size="20" style="width: 160px; float: left; margin-right: 1%;">
</div>
<div align="left">
<input type="text" required style="width: 160px; float: left; margin-right: 1%;" size="20" placeholder="Obtained Marks in Matic" id="matric" name="matric" class="TextBox form-control">
<input type="text" required class="TextBox form-control" placeholder="Total Marks in Matric" name="totalmatric" size="20" style="width: 160px">
</div>
<div class="style1">NET Marks (out of 200)</div>
<label for="1">
<input type="text" required style="width: 160px" size="20" id="per" class="TextBox form-control">
<br>
</label>
<center>
<input type="submit" onClick="myFunction()" name="submit" value="Find Colleges" id="INPUT_27">
</center>
</form>
【问题讨论】:
-
您能告诉我们您是如何解决这个问题的吗?您只给了我们一些 HTML。你在哪里挣扎?
-
@domyos eduvision.edu.pk/merit/nust-merit-calculator.php 我需要创建正确验证的链接是什么,你能帮我做吗?
-
@ArsalanEhsan 如果用户回答了您的问题,也请接受他的回答 (Accepting Answers: How does it work?)。如果不是,请说明什么仍未得到答复,这是 StackOverflow 的一个非常重要的部分,非常感谢。
标签: javascript jquery html validation