I'm trying to display specific divisions based on a dropdown selection here, In my example,, I have two different dropdown options followed by two different divs. I want to show only one of these two divs based on the selected value and keep the other divs hidden.
For example, If Option 1: House Inspection is selected, then the content in div class="house" should be displayed.
PHP
<!-- PHP CodeIgniter Render Select Instead of HTML Select-->
<div class="col-md-12" >
<?php
$subject = [0 => ["id" => "House", "name" => _l("House Inspection") ], 1 => ["id" => "Plot", "name" => _l("Plot Inspection") ], "name" => _l("Farm House Inspection") ]];
$value = isset($subject) ? $disscussion->subject : "";
echo render_select("subject", $subject, ["id", "name"], "Inspection Type:", $value);
?>
</div>
<div class="house">
<?php echo render_textarea('house', 'project_discussion_description'); ?>
</div>
<div class="plot">
<?php echo render_textarea('plot', 'project_discussion_description'); ?>
</div>
<script>
jQuery(document).ready(function($){
$('select[name=subject]').change(function () {
// hide all optional elements
$('.house').css('display','none');
$('.plot').css('display','none');
$("select[name=subject] option:selected")
.each(function () {
if($(this).val() == "House" || "Plot") {
$('.subject').css('display','block');
} else if($(this).val() == "House") {
$('.house').css('display','block');
} else if($(this).val() == "Plot") {
$('.plot').css('display','block');
}
});
});
});
</script>