Search the Community
Showing results for tags 'dependant combobox'.
-
I am trying to update the second select box 'subcategory_id' but I don't know how to return the query values back to the control/twig template. All of the examples I have seen echo back html from a option while loop. Should I be echo back the html as per other common examples or is there a more twig compliant way to do this, maybe returning an array variable. Thanks in advance, James catalogues.php <script> $('#category_id').change( function() { checkCategory(); // checks value and enables/disables subcategory control var catid = $(this).val(); var dataString = 'catid='+catid; $.ajax ({ type: "POST", url: "catalogues.php", data: dataString, cache: false, success: function() { $("#subcategory_id")..........; // ????? } }) }); </script> <?php if(isset($_POST['catid'] )) { $catid=$_POST['catid']; $sql_subcategory = "SELECT catalogues_categories.id, catalogues_categories.category, catalogues_categories.parent_id, catalogues_categories.inuse FROM catalogues_categories WHERE catalogues_categories.parent_id = {$catid} AND catalogues_categories.inuse = 1 ORDER BY catalogues_categories.category ASC"; $query_subcategory = $conn->query($sql_subcategory); $results_subcategory = $query_subcategory->fetchAll(); } else { $results_subcategory = null; } ?>