1
Today I have a persistence problem in the select field of categories and subcategories I made 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 it to be possible to persist with the data that is in the database, so that the user when editing the post, have to be selecting again the categories and subcategories.
No one to help with this problem?
– Alisson Maciel