i have 3 dropdown lists:
- disease classifications.
- disease categories.
- disease parent.
values in the categories depend on classifications while values in parent depend on categories. values in classifications populated from an array while for categories are coming from database. i have a problem at 2nd dropdown list. suppose whenever user has selected a value, the form will be submitted using onChange=“this.form.submit()” and the selected value supposely can be viewed in the 2nd dropdown list and values in 3rd dropdown list will appear. but, the truth is, the selected value gone after made selection. how to solve that?
disease_block.php
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
include("../ecis_cfg.php");
global $ecisDisease, $ecisDiseaseCategory;
$dcid = isset($_GET['dcid']) ? $_GET['dcid'] : ' ';
//echo "dcid: " . $dcid;
$discatid = isset($_GET['discatid']) ? $_GET['discatid'] : ' ';
//echo "<br>discatid: " . $discatid;
?>
<style type="text/css">
@import url(../css/style_registration.css);
.style3 {font-size: 13px}
body,td,th {
font-size: 13px;
}
</style>
<form name="form" method="post" action="../process/disease.php?op=register">
<table width="464" border="0">
<tr>
<td colspan="2" id="tblheader">Disease Profile </td>
</tr>
<tr>
<td width="114">Classification</td>
<td width="334">
<select name="dis_class" id="dis_class" onChange="this.form.submit();">
<option value="" selected>Select</option>
<?php
foreach($ecisDiseaseCategory->loadDiseaseClassfication() as $key => $value){
?>
<?php if($key == $dcid){ ?>
<option value="<?php echo $key; ?>" selected>[<?php echo $key; ?>] <?php echo $value; ?></option>
<?php } else { ?>
<option value="<?php echo $key; ?>">[<?php echo $key; ?>] <?php echo $value; ?></option>
<?php } } ?>
</select>
</td>
</tr>
<tr>
<td>Category</td>
<td>
<select name="dis_cat" id="dis_cat" onChange="this.form.submit();">
<option selected>Select</option>
<?php $ecisDiseaseCategory->loadDiseaseCategory($dcid); ?>
</select>
</td>
</tr>
<tr>
<td>Name</td>
<td><input name="dis_name" type="text" id="dis_name"></td>
</tr>
<tr>
<td>Description</td>
<td><textarea name="dis_desc" id="dis_desc"></textarea></td>
</tr>
<tr>
<td>Parent</td>
<td>
<select name="dis_parent" id="dis_parent">
<option selected>Select</option>
<option value="0">None</option>
<?php $ecisDisease->loadDiseaseParent($discatid); ?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit"></td>
<td> </td>
</tr>
</table>
</form>
disease.php
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
include("../ecis_cfg.php");
global $ecisDisease;
# 1st dropdown list:
# 1. contains classification of diseases
if(!isset($_POST['Submit'])){
if(isset($_POST['dis_class']) && ($_POST['dis_class'] != "Select") && (isset($_GET['op']) == "register")){
header("Location: ../templates/disease_block.php?dcid=".$_POST['dis_class']);
}
}
# 2nd dropdown list:
# 1. data for this 2nd dropdown list depends on selected classification of diseases (from 1st dropdown list)
# 2. select any value from this 2nd dropdown list, will populate data into 3rd dropdown list
if(!isset($_POST['Submit'])){
if(isset($_POST['dis_cat']) && ($_POST['dis_cat'] != "Select") && (isset($_GET['op']) == "register")){
header("Location: ../templates/disease_block.php?dcid=".$_POST['dis_class']."&discatid=".$_POST['dis_cat']);
}
}
# if submit button is clicked
if(isset($_POST['Submit']) && isset($_GET['op']) == "register"){
if(empty($_POST['dis_class']) || empty($_POST['dis_cat']) || empty($_POST['dis_name']) || $_POST['dis_parent'] == "Select"){
echo "<strong>Warning:</strong> Please fill in all mandaratory fields.";
echo "<br><br>";
echo "<a href=\\"../templates/disease_block.php\\">Back</a>";
}
else{
if($ecisDisease->checkDisease($_POST['dis_cat'], $_POST['dis_name']) == false){
echo "<strong>Warning:</strong> <strong><u>" . $_POST['dis_name'] . "</u></strong> already in the records.";
echo "<br><br>";
echo "<a href=\\"../templates/disease_block.php\\">Back</a>";
}
else
$ecisDisease->addDisease($_POST['dis_cat'], $_POST['dis_name'], $_POST['dis_desc'], $_POST['dis_parent']);
}
}
?>
functions involved
#1st dropdown list
function loadDiseaseClassfication()
{
$diseaseClass = array("I" => "Certain infectious & parasitic diseases",
"II" => "Neoplasms",
"III" => "Blood & blood-forming organs",
"IV" => "Endocrine, nutritional & metabolic diseases",
"V" => "Mental & behavioural disorders",
"VI" => "Nervous system",
"VII" => "Eye & adnexa",
"IX" => "Ear & mastoid process",
"X" => "Respiratory system",
"XI" => "Digestive system",
"XII" => "Skin & subcutaneous tissue",
"XIII" => "Musculoskeletal system & connective tissue",
"XIV" => "Genitourinary system",
"XV" => "Pregnancy, childbirth & the puerperium",
"XVI" => "Certain conditions originating in the perinatal period",
"XVII" => "Congenital malformations, deformations & chromosomal abnormalities"
);
return $diseaseClass;
}
#2nd dropdown list
function loadDiseaseCategory($classId)
{
global $ecisDB, $parent;
$parent = 0;
$sql = "SELECT *
FROM DiseaseCategory
WHERE diseaseCategoryClass = '$classId'
AND diseaseCategoryParent = '$parent'
ORDER BY diseaseCategoryName";
$query = $ecisDB->query($sql) or die(mysql_error());
$count = $ecisDB->sql_count($query);
if($count <> 0){
while($result = $ecisDB->fetch_array($query)){
echo '<option value="'.$result["diseaseCategoryId"].'">'.$result["diseaseCategoryName"].'</option>';
}
}
}
#3rd dropdown list
function loadDiseaseParent($discatid)
{
global $ecisDB, $parent;
$parent = 0;
$sql = "SELECT * FROM Disease WHERE diseaseCategoryId = '$discatid' AND diseaseParent = '$parent'";
$query = $ecisDB->query($sql) or die(mysql_error());
$count = $ecisDB->sql_count($query);
if($count <> 0){
while($result = $ecisDB->fetch_array($query)){
echo '<option value="'.$result["diseaseCategoryId"].'">'.$result["diseaseName"].'</option>';
}
}
}