0
<section id="contact" class="contact">
      <div class="container">

        <div class="section-title">
          <h2 data-aos="fade-up">Insert ISR</h2>

        </div>


        <div class="row justify-content-center" data-aos="fade-up" data-aos-delay="300">
          <div class="col-xl-9 col-lg-12 mt-4">
            <form action="../proses" method="post" >
              <div class="form-group">

                <div class="form-group">
                  <label  class="font-weight-bold" for="fullname" >Bisnis Unit</label>
                  <select class="form-control" name="bisnisunit" id="bs" required>
                    <option>Bisnis Unit</option>
                    <?php

                    $query2 = mysqli_query($con,"SELECT * FROM bisnisunit ");
                    while($data = mysqli_fetch_array($query2)) {
                      ?>
                      <option><?php echo $data['bisnisunit']; ?></option>
                      <?php
                    } 
                    ?>

                  </select>
                </div>
                <div class="form-group">
                  <label  class="font-weight-bold" for="fullname">Cabang</label>
                  <select class="selectpicker form-control" data-live-search="true" name="cabang" id="cbn" required>
                    <option>Cabang</option>
                  </select>
                </div>
              
              <div class="form-group">
                <input type="submit" value="save" name="insertcabang" class="btn btn-success btn-lg" />
              </div>
            </form>
          </div>

        </div>

      </div>
    </section>

  

  <script>

            $("#bs").change(function(){

              var id_bisnis = $("#bs").val();

                $.ajax({
                  type: "POST",
                  dataType: "html",
                  url: "getcabang.php",
                  data: "bs="+id_bisnis,
                  success: function(msg){
                        if(msg == ''){

                           swal("Failed!", "Masukan Pilihan !", "error");
                        }

                        else{

                          $("#cbn").html(msg).selectpicker();
                                                                               
                        }
                   }
               });    
            });
        </script>`

I want to add a search for select but, when I add a selectpicker to the select tag the code created for change select branch doesn't work. Meanwhile, when I delete the selectpicker, my code runs normally, that is, when I select one of the business units, select on the branch will display the name of the branch that matches the selected business unit only. what is the solution?

  • _“what is the solution?”_ - probably to go and check the documentation of your “select picker”, to see if that needs any specific events to be processed or method to be called, to handle the change and read the value. – CBroe Apr 06 '21 at 07:42
  • do you have an example? because i am newbie to selectpicker and ajax. – Dimas Pratama Apr 06 '21 at 08:05
  • `when I add a selectpicker to the select tag the code created for change select branch doesn't work` - what selectpicker? What does `doesn't work` mean? Some errors? Please edit your question and try to clarify. It will be easier for ppl to help if you can also create a [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve) - there is a lot of HTML above which has nothing to do with the problem, and the HTML we *do* need to see (the ` – Don't Panic Apr 06 '21 at 08:08
  • yes, so I want select on the branch to be filtered based on the select business unit. For example, when I select the Toyota business unit, the select branch will display a list of Toyota-specific branches. when I don't use selectpicker on then the select branch will not display a list of special Toyota branches. – Dimas Pratama Apr 06 '21 at 10:28
  • You still didn't clarify what a `selectpicker` is, nor what selectpicker you are using ... AFAICT you are trying to populate a 2nd select based on what is chosen in the 1st select.? There are *many* duplicates showing how to do that here on SO, do they help? Eg https://stackoverflow.com/q/8749326/6089612, https://stackoverflow.com/q/34409769/6089612, https://stackoverflow.com/q/10570904/6089612, https://stackoverflow.com/q/22991067/6089612, https://stackoverflow.com/q/11237900/6089612, ... – Don't Panic Apr 06 '21 at 11:41

0 Answers0