Create persistence of categories and subcategories with jquery

1

Now I have a persistence problem in the select field of categories and subcategories that I did with jquery with the help of a video, since I'm not very good with jquery.

I have the following jquery script:

<script type="text/javascript">
   $(document).ready(function () {

     $("select[name=post_category]").change(function () {
        $("select[name=post_category_parent]").html('<option value="0">Carregando...</option>');

         $.post("<?= INCLUDE_PATH ?>/modulos/combo_subcategoria.php",
                {post_category: $(this).val()},
                function (valor) {
                     $("select[name=post_category_parent]").html(valor);
                }
         )
       })
   })
</script>

And I have my selects:

<div class="form-group">
      <label for="post_category"><strong>Categoria</strong></label>
      <select name="post_category" id="post_category" class="subcategoria form-control" required="">
           <option value="" disabled="" selected="">Selecione a categoria</option>
           <?php
              $cattype = 'categoria';
              $type = "evento";
              $read->ExeRead("ws_categories", 
                             "where category_type = :cattype and type = :type and category_parent = 0", 
                             "cattype={$cattype}&type={$type}");
              if ($read->getResult()):
                  foreach ($read->getResult() as $cat_form):
           ?>                                                                                
          <option value="<?= $cat_form->category_id; ?>"><?= $cat_form->category_title; ?></option>
          <?php
                  endforeach;
              endif;
          ?>
        </select>
</div>
<div class="form-group">
       <label for="post_category_parent"><strong>Subcategoria</strong></label>
       <select name="post_category_parent" id="post_category_parent" class="subcategoria form-control" required="">
             <option value="" disabled="" selected="">Subcategoria</option>
             <option value="" disabled="">Selecione a categoria</option>
      </select>
</div>

I wanted to be persistent with the data that is in the database, so that the user when editing the post, has to be selecting categories and subcategories again.

    
asked by anonymous 13.07.2017 / 05:07

0 answers