how to display a select option when an initial select option is clicked with jquery

Posted 1 year ago by icelander

hi guys. this is my code but its not working

<script>
        function showcategory(){
            var selectBox = document.getElementById('category');
            var userInput = selectBox.options[selectBox.selectedIndex].value;
            if (userInput == $sel->id){
                document.getElementById('description').style.visibility = 'visible';
            }else{
                document.getElementById('description').style.visibility = 'hidden';
            
            }
            return false;
        }
        
        
        </script>
    </head>

this is my select option to initially select 

Select Category
                                         <select class="form-control" id="category" name="category" onchange="return showcategory();">
                                                 @foreach($category as $sel)
                                         <option value=" {{$sel->id}}"> {{$sel->category}} </option>
                                         @endforeach
                                         </select> 
                                     </div>
this is the select option I want to be displayed with contents based on the previously selected option

@foreach($catid as $describe) {{$describe->problems}} @endforeach
                                                  </select>

am using Laravel. thanks

Please sign in or create an account to participate in this conversation.