因此,如果两个验证都可以单独工作(如果我只是在没有微调器验证的情况下将单选按钮验证放在函数中,那么单选按钮验证就可以工作,反之亦然),那么当我将两个验证都放在函数中时,顶部验证是单选验证有效,但作为微调器验证的底部验证不显示消息?
Code is below:
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Create a Session</title>
<script type="text/javascript">
function validation() {
var errMsgO = document.getElementById("radioAlert");
var btnRadioO = document.getElementsByName("sessionNo");
var isbtnRadioChecked = false;
var errQuesMsgO = document.getElementById("numberAlert");
var questionNumberO = document.getElementsByName("txtQuestion");
for(i=0; i < btnRadioO.length; i++){
if(btnRadioO[i].checked){
isbtnRadioChecked = true;
}
}
if(!isbtnRadioChecked) {
errMsgO.innerHTML = "Please Select the Number of Sessions you Require";
} else {
errMsgO.innerHTML = "";
}
return false;
if(questionNumberO[0].value == 0){
errQuesMsgO.innerHTML = "Please Set the Number of Questions";
} else {
errQuesMsgO.innerHTML = "";
}
return false;
}
</script>
</head>
<body>
<form action="create_session.php" method="post" name="sessionform">
<table>
<tr>
<th>2: Number of Sessions :</th>
<td class="sessionNo"><input type="radio" name="sessionNo" value="1" />1</td>
<td class="sessionNo"><input type="radio" name="sessionNo" value="2" />2</td>
<td class="sessionNo"><input type="radio" name="sessionNo" value="3" />3</td>
<td class="sessionNo"><input type="radio" name="sessionNo" value="4" />4</td>
<td class="sessionNo"><input type="radio" name="sessionNo" value="5" />5</td>
</tr>
</table>
<div id="radioAlert"></div>
<table>
<tr>
<th>Number of Questions:</th>
<td class="spinner"><textarea class="spinnerQuestion" name="txtQuestion" id="txtQuestion" cols="2" rows="1"></textarea></td>
<td><button class="scrollBtn" id="btnQuestionUp"><img src="Images/black_uppointing_triangle.png" alt="Increase" /></button>
<button class="scrollBtn" id="btnQuestionDown"><img src="Images/black_downpointing_triangle.png" alt="Decrease" /></button></td>
</tr>
</table>
<div id="numberAlert"></div>
<p><input class="questionBtn" type="button" value="Prepare Questions" name="prequestion" onClick="validation()" /></p> <!-- Prepare Questions here-->
</form>
</body>