次のコードでは、選択オプションまたはテキスト フィールドの値を処理しようとしています。
<script>
function check() {
var dropdown = document.getElementById("OpType");
var current_value = dropdown.options[dropdown.selectedIndex].value;
if (current_value == "OpNo") {
document.getElementById("operationno").style.display = "block";
document.getElementById("MainType").style.display = "none";
document.getElementById("MemName").style.display = "none";
document.getElementById("EmpName").style.display = "none";
<?php $TPE = '1'?>
}
else if (current_value == "OpTyp") {
document.getElementById("MainType").style.display = "block";
document.getElementById("MemName").style.display = "none";
document.getElementById("EmpName").style.display = "none";
document.getElementById("operationno").style.display = "none";
<?php $TPE = '2'?>
}
else if (current_value == "OpMem") {
document.getElementById("MemName").style.display = "block";
document.getElementById("operationno").style.display = "none";
document.getElementById("MainType").style.display = "none";
document.getElementById("EmpName").style.display = "none";
<?php $TPE = '3'?>
}
else if (current_value == "OpEmp"){
document.getElementById("MemName").style.display = "none";
document.getElementById("operationno").style.display = "none";
document.getElementById("MainType").style.display = "none";
document.getElementById("EmpName").style.display = "block";
<?php $TPE = '4'?>
}
else if (current_value == "blank") {
document.getElementById("MainType").style.display = "none";
document.getElementById("MemName").style.display = "none";
document.getElementById("EmpName").style.display = "none";
document.getElementById("operationno").style.display = "none";
<?php $TPE = '0'?>
}
}
</script>
<form name="f1" action="FollowOperations.php" method="post">
<select id="OpType" onChange="check();">
<option value="blank">Choose</option>
<option value="OpNo">Operation No</option>
<option value="OpTyp">Operation Type</option>
<option value="OpMem">Maintenance Member</option>
<option value="OpEmp">Employee</option>
</select><br>
<input class="tb10" type="text" id="operationno" size="4" style="text-align: center" style="display: none">
<select id="MainType" style="display: none">
<option value="blank">Choose</option>
<option value="printing">Printing</option>
<option value="maintenance">PC Maintenance</option>
<option value="internet">Internet Problem</option>
<option value="software">Software</option>
<option value="email">Email Problem</option>
<option value="usbcd">USB/CD Problem</option>
</select>
<select id="MemName" style="display: none">
<option value="blank">Choose</option>
<option value="john">John</option>
<option value="hen">Hen</option>
</select>
<select id="EmpName" style="display: none">
<option value="blank">Choose</option>
<option value="smith">Smith</option>
<option value="will">William</option>
<option value="Gor">George</option>
</select>
<input type="submit" value="Submit" class="button" />
</form>
<?php
if (isset($_POST['formsubmitted'])){
if ($TPE == '1'){
$operationno = $_POST['operationno'];
$query_retrieve_maintenance = "Select Type from Maintenance where ID = '$operationno'";
$result_retrieve_maintenance = mysqli_query($dbh, $query_retrieve_maintenance);
$maintenance_type = mysqli_fetch_row($result_retrieve_maintenance);
$maintenance_typet = $maintenance_type[0];
echo $maintenance_typet;
} else if ($TPE == '2'){
$MainType = $_POST['MainType'];
if ($MainType=='email'){echo 'Email is not ava';}
} else if ($TPE == '3'){
$MemName = $_POST['MemName'];
} else if ($TPE == '4'){
$EmpName = $_POST['EmpName'];
} else{
$msg = 'not available';
}
}
?>
コードでわかるように、ユーザーが操作番号を選択すると、テキスト フィールドが表示され、ユーザーは操作番号を入力して、このメンテナンス操作のタイプを表示します。同様に、ユーザーが操作タイプを選択すると、メンテナンス タイプのリストが表示され、ユーザーは必要な操作のタイプを選択し、残りの選択オプションについても同様に選択できます。
私が直面している問題は、ユーザーが選択または入力したものを処理することです(操作番号で検索する場合)。コードでわかるように、使用if (isset($_POST['formsubmitted'])){
しましたが機能しませんでした。どんな提案でも。