我有两个选择的输入ID_1
和ID_2
,我希望看到第三个只读输入Result
的结果
示例:
ID_1 = 1 and ID_2 = 1 then RESULT = "Correct"
ID_2 = 1 and ID_1 = 2 then RESULT = "Fail"
ID_1 = 1 and ID_2 = 2 then RESULT = "Fail"
ID_1 = 2 and ID_2 = 2 then RESULT = "Fail"
你好社区
我需要以下帮助。我目前有以下HTML代码,其中包含两个选择条目
我需要一个JavaScript脚本,该脚本根据选择验证两个条目(ID_1)和(ID_2)的结果,以在条目(Result)中给出结果
比较逻辑应为以下内容:
ID_1 = 1 and ID_2 = 1 then Result = "Aproved"
ID_1 = 1 and ID_2 = 2 then Result = "Fail"
ID_2 = 1 and ID_1 = 2 then Result = "Error"
我仍然关注您的评论。
我尝试创建部分代码,但我不知道如何继续,请帮助
//<script language="javascript">
function validation()
var Sino_1 = document.form.ID_1.value;
var Sino_2 = document.form.ID_2.value;
if (ID_1 = 1 && ID_2 = 1)
//</script>
<html>
<head>
<title>Validation report</title>
</head>
<body>
<fieldset>
<footer>
<form id=form>
<h2 class="encabezados" align="center">Validation report</h2>
Question 1?<br><select name="ID_1" id="ID_1" required>
<option value="0">Select</option>
<option value="1">Yes</option>
<option value="2">Not</option>
</select>
<br><br>Question 1<br><select name="ID_2" id="ID_2" required>
<option value="0">Select</option>
<option value="1">Yes</option>
<option value="2">Not</option>
</select>
<br><br><button onclick="Validation" class="button" align="center" type="submit">Validation</button>
<br><br>Result<input type="text" name="Result" id="Result" readonly>
</form>
</footer>
</fieldset>
</body>
</html>
答案 0 :(得分:0)
您的html和javascript代码中几乎没有错误。 请检查以下代码,我已提到代码中的错误。
<!DOCTYPE html>
<html>
<head>
<title>Validation report</title>
<body>
<fieldset>
<footer>
<form id=form>
<h2 class="encabezados" align="center">Validation report</h2>
Question 1?
<br>
<select name="ID_1" id="ID_1" required>
<option value="0">Select</option>
<option value="1">Yes</option>
<option value="2">Not</option>
</select>
<br>
<br>Question 1
<br>
<select name="ID_2" id="ID_2" required>
<option value="0">Select</option>
<option value="1">Yes</option>
<option value="2">Not</option>
</select>
<br>
<br>
<!-- wrong function name validation -->
<!-- type="submit" TO type="button"-->
<button onclick="validation()" class="button" align="center" type="button">Validation</button>
<br>
<br>Result
<input type="text" name="Result" id="Result" readonly>
</form>
</footer>
</fieldset>
</head>
</body>
<script language="javascript">
// missing function brackets {}
function validation() {
// use getElementById to get value
var Sino_1 = document.getElementById('ID_1').value;
var Sino_2 = document.getElementById('ID_2').value;
// var Sino_1 = document.form.ID_1.value;
// var Sino_2 = document.form.ID_2.value;
/// = TO ==
// AND user Sino_1 , Sino_2
if (Sino_1 == 1 && Sino_2 == 1) {
document.getElementById('Result').value = 'Aproved';
}
else if (Sino_1 == 1 && Sino_2 == 2) {
document.getElementById('Result').value = 'Fail';
}
else if (Sino_1 == 2 && Sino_2 == 1) {
document.getElementById('Result').value = 'Error';
}
else
{
document.getElementById('Result').value = '';
}
}
</script>
</html>