我有一个您可以在这里访问的应用程序:应用程序
现在在应用程序中,将模块下拉菜单留给Please Select
选项并提交。您将看到一条消息显示选择一个模块。所以现在从下拉列表中选择一个模块并提交。您可以看到它Assessment
在下方显示一个下拉菜单(与该模块相关的评估)。
现在我希望Assessment
下拉菜单的执行方式与Module
下拉菜单相同。如果没有选择评估,则在下方显示一条消息,如果选择了评估,则在下方显示下一个表单,Assessment
下拉菜单和提交仍然像Module
下拉菜单一样显示,并且提交仍然显示在页面上。
问题是,您将能够看到您是否选择评估选项,而是它被下一个表单块替换(显示多个选择框)。如果用户在提交时没有在下拉菜单中选择评估,我希望不显示选择框,或者如果选择评估,则在评估下拉菜单和提交按钮下方显示它,而不是替换它。
但是是什么导致了这种情况,我可以让它执行它应该做的功能吗?
以下是代码的简化版本:
代码:
<script type="text/javascript">
function validation(e) {
var isDataValid = true;
var moduleTextO = document.getElementById("modulesDrop");
var errModuleMsgO = document.getElementById("moduleAlert");
if (moduleTextO.value == ""){
$('#targetdiv').hide();
$('#assessmentForm').hide();
errModuleMsgO.innerHTML = "Please Select a Module";
isDataValid = false;
}else{
errModuleMsgO.innerHTML = "";
$('#assessmentForm').show();
}
if (isDataValid === false)
{
if (e.preventDefault)
{
e.preventDefault();
e.stopPropagation();//VERY important
}
e.returnValue = false;
e.cancelBubble = true;
}
return isDataValid;
}
function sessionvalidation(e) {
var isDataValid = true;
var sessionTextO = document.getElementById("sessionsDrop");
var errAssesMsgO = document.getElementById("assessmentAlert");
if (sessionTextO.value == ""){
$('#assessmentdiv').hide();
$('#studentExistForm').hide();
errAssesMsgO.innerHTML = "Please Select an Assessment";
isDataValid = false;
}else{
errAssesMsgO.innerHTML = "";
$('#studentExistForm').show();
$('#assessmentForm').show();
}
if (isDataValid === false)
{
if (e.preventDefault)
{
e.preventDefault();
e.stopPropagation();//VERY important
}
e.returnValue = false;
e.cancelBubble = true;
}
return isDataValid;
}
</script>
<?php
$moduleHTML = "";
$moduleHTML .= '<select name="modules" id="modulesDrop">'.PHP_EOL;
$moduleHTML .= '<option value="">Please Select</option>'.PHP_EOL;
$moduleHTML .= '</select>';
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" onsubmit="return validation(event);">
<table>
<tr>
<th>Module: <?php echo $moduleHTML; ?></th>
</tr>
</table>
<p><input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" /></p>
<div id="moduleAlert"></div>
<div id="targetdiv"></div>
</form>
<?php
if (isset($_POST['moduleSubmit'])) {
$moduleInfo = explode("_", $_POST['modules']);
$moduleNo = $moduleInfo[0];
$moduleName = $moduleInfo[1];
$moduleId = $moduleInfo[2];
$outputmodule = sprintf("<p><strong>Selected Module:</strong> %s - %s <input type='hidden' value='%s'></p>", $moduleNo, $moduleName, $moduleId);
$sessionHTML = '';
$sessionHTML = '<select name="session" id="sessionsDrop">'.PHP_EOL;
$sessionHTML .= '<option value="">Please Select</option>'.PHP_EOL;
$sessionHTML .= sprintf("<option value='%s'>%s - %s - %s</option>", $dbSessionId, $dbSessionName, date("d-m-Y",strtotime($dbSessionDate)), date("H:i",strtotime($dbSessionTime))) . PHP_EOL;
$sessionHTML .= '</select>';
$assessmentform = "<div id='lt-container'>
<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post' id='assessmentForm'>
{$outputmodule}
<p><strong>Assessments:</strong> {$sessionHTML} </p>
<p><input id='assessmentSubmit' type='submit' value='Submit Assessment' name='assessmentSubmit' /></p>
<div id='assessmentAlert'></div>
<div id='assessmentdiv'></div>
</form>
</div>";
echo $assessmentform;
}
if (isset($_POST['assessmentSubmit'])) {
$studentHTML = '';
$studentSELECT = '<select name="studenttextarea" id="studentselect" size="6">'.PHP_EOL;
$studentSELECT .= "<option disabled='disabled' class='red' value=''>No Students currently in this Assessment</option>";
$studentSELECT .= sprintf("<option disabled='disabled' value='%s'>%s - %s %s</option>", $dbStudentId, $dbStudentAlias, $dbStudentForename, $dbStudentSurname) . PHP_EOL;
$studentSELECT .= '</select>';
$studentexist="
<form id='studentExistForm'>
<p><strong>Current Active Students in Assessment:</strong></p>
<p>{$studentSELECT}</p>
</form>
</div>";
echo $studentexist;
}
?>