I have two interdependent drop drown, 2nd drop down value populates when 1st drop down value selected, When i select 2nd drop down it has to populate text boxes with the values stored in database.
My drop down list is working but i am not getting how to populate text boxes when 2nd drop down selected.
Here is my code
jquery
<script>
function showItems(sel) {
var cat_id = sel.options[sel.selectedIndex].value;
$("#output1").html( "" );
if (cat_id.length > 0 ) {
$.ajax({
type: "POST",
url: "fetch_items.php",
data: "cat_id="+cat_id,
cache: false,
beforeSend: function () {
$('#output1').html('<img src="loader.gif" alt="" width="24" height="24">');
},
success: function(html) {
$("#output1").html( html );
}
});
}
}
</script>
Form(dropdown)
<div class="formSep">
<?php
$sql2 = "SELECT * FROM item_category";
$query2 = mysql_query($sql2);
?>
<select name="category" onChange="showItems(this);">
<option value="">Item Category</option>
<?php while ($rs2 = mysql_fetch_array($query2)) { ?>
<option value="<?php echo $rs2["item_id"]; ?>"><?php echo $rs2["name"]?></option>
<?php } ?>
</select>
<div id="output1"></div>
fetch_items.php
<?php
error_reporting(0);
include("../connect.php");
include("../admin_auth.php");
$cat_id = ($_REQUEST["cat_id"] <> "") ? trim( addslashes($_REQUEST["cat_id"])) : "";
if ($cat_id <> "" ) {
$sql = "SELECT * FROM items where category=".$cat_id."";
$count = mysql_num_rows( mysql_query($sql) );
if ($count > 0 ) {
$query = mysql_query($sql);
?>
<select name="items">
<option value="">Items</option>
<?php while ($rs = mysql_fetch_array($query)) { ?>
<option value="<?php echo $rs["name"]; ?>"><?php echo $rs["name"]; ?></option>
<?php } ?>
</select>
<?php
}
}
?>
in textboxes i should get values from items table, for that query
$m1 = "select * from order_line_items where order_id=".$order_id."";
$result = mysqli->query($m1);
$row = $result->fetch_array(MYSQLI_ASSOC);
Please suggest me how to generate text boxes.