Dynamic Select Box / Php, Mysql, Jquery
hi all,
i having problems dynamic select box. have read few tutorials , have tried best fit code layout not having luck. have 2 select boxes populated dynamically, in 2 seperate tables.
parent child (sub)
id - name sub_id - parent_id - sub_name
here forum code:
<p>
<label for="category_id">category :</label>
<select name="category_id" id="category_id">
<option value="0">-- select category --</option>
<?php
foreach ($categories $row) {
echo "<option value='{$row['category_id']}'";
if ($errors && $_post["category_id"] == $row['category_id']) {
echo 'selected="selected"';
}
echo ">{$row['category_name']}</option>";
}
?>
</select>
<script>
$(document).ready(function() {
$('#category_id').change(function() {
var category_id = $(this).val();
if(category_id != '') {
$.ajax({
type: "post",
url: "get_child_categories.php",
data: "category_id="+ category_id,
success: function(option) {
$("#sub_category_id").html(option);
}
});
}
else
{
$("#sub_category_id").html("<option value=''>-- select sub category --</option>");
}
return false;
});
});
</script>
<label for="sub_category_id">sub category :</label>
<select name="sub_category_id" id="sub_category_id">
<option value="">-- select sub category --</option>
</select>
</p>
the get_child_categories.php
$sub_category = getallsubcategories($dbread, $category_id);
if(isset($_post['category_id']) && $_post['category_id'] != '')
{
$category_id = $_post['category_id'];
foreach ($sub_category $row) {
echo "<option value='{$row['sub_category_id']}'";
if ($errors && $_post["sub_category_id"] == $row['sub_category_id']) {
echo 'selected="selected"';
}
echo ">{$row['sub_category_name']}</option>";
}
}
both make calls connect.php username/password/hostname , definitions.php page each function created drop downs.
any great, not talented jquery user, little experience. appreciate time , if need more info please let me know!
thanks!
More discussions in Develop server-side applications in Dreamweaver
adobe
Comments
Post a Comment