Welcome Guest, Not a member yet? Register   Sign In
Displaying Div Based on Dropdown Selection in CodeIgnator Using Jquery
#1

(This post was last modified: 12-19-2022, 09:20 PM by HumeleJotesane.)

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 echatspin echatrandom 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] optionConfusedelected")
            .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>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB