形式:2条分开的道路

时间:2018-10-15 21:18:39

标签: javascript html forms

我正在为一个简单的工作表格工作。我在网上找到了一些代码,并一直在使用它。它开始问一个简单的问题。学生有身份证吗?这是“是”或“否”的切换。如果选择“是”,则它将从数据库中提取学生信息并显示。如果为“否”,则将弹出单独的框,询问学生ID,姓氏,名字,DOB等。现在,我专注于选择工作路径。我没有运气。

function admSelectCheck(nameSelect) {
  if (nameSelect) {
    admOptionValue = document.getElementById("admOption").value;
    if (admOptionValue == nameSelect.value) {
      document.getElementById("admDivCheck").style.display = "block";
    } else {
      document.getElementById("admDivCheck").style.display = "none";
    }
  } else {
    document.getElementById("admDivCheck").style.display = "none";
  }
}
Student ID
<select id="getFname" onchange="admSelectCheck(this);">
  <option value="6"></option>
  <option value="1">Yes</option>
  <option id="admOption" value="0">No</option>

</select>


<div id="admDivCheck" style="display:none;">
  <br><br>
  <form action="/action_page.php" method="post">
    Please enter ID# <input type="number" name="ID"><br> Last Name <input type="text" name="last"><br> First Name <input type="text" name="first"><br>
    <button type="submit">Submit</button>
</div>

1 个答案:

答案 0 :(得分:0)

这个怎么样? 。

function admSelectCheck(nameSelect) {
	
	var value = nameSelect.value;

	if (value == "1") {
		document.getElementById("id-form").style.display = "block";
		document.getElementById("second-div").style.display = "none";
	} else if (value == "0"){
		document.getElementById("id-form").style.display = "none";
		document.getElementById("second-div").style.display = "block";
	}
	else{
		document.getElementById("id-form").style.display = "none";
		document.getElementById("second-div").style.display = "none";
	}
	
}
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Document</title>
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
		<script type="text/javascript" src = "test.js"></script>
	</head>
	<body>
		Student ID
		<select id="getFname" onchange="admSelectCheck(this);">
			<option value="6"></option>
			<option value="1">Yes</option>
			<option id="admOption" value="0">No</option>
		</select>

		<form id = "id-form" action="/action_page.php" method="post" style = "display: none">
			Please enter ID# <input type="number" name="ID"><br> 
			Last Name <input type="text" name="last"><br>
			First Name <input type="text" name="first">
			<br>
			<button type="submit">Submit</button>
		</form>
		<div id = "second-div" style = "display: none">
			<br>
			<img src = "https://i.ytimg.com/vi/QuTLRz8Nli0/hqdefault.jpg"/>
		</div>
	</body>
</html>