-2
I have a form that shows the lines(departments) and the families(categories) of products. I’m trying to improve the register by populating the family combobox, so select the line, returning the families that are linked to the selected line. I can show the right div when it is product inclusion, but when it is to update, the families combobox is not displayed.
Follows my code:
php lines.
<?php
include '../url_seo.php';
include 'config/config.inc.php';
include "funcoes/conexao.php";
conecta();
$cd_itprod = '786454';
$query = "select * from ti_produtos where cd_itprod= '".$cd_itprod."'";
$resul = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_object($resul);
$cd_linha = $row->cd_linha;
$cd_familia = $row->cd_familia;
?>
<html>
<head>
<title>Atualizando combos com jquery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="<?= $url_seo; ?>js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#cd_linha').change(function(){
$('#familia').load('listaFamilias.php?cd_linha='+$('#cd_linha').val());
});
});
</script>
</head>
<body>
<h1>Atualizando combos com jquery</h1>
<label>cd_linha:</label>
<select name="cd_linha" id="cd_linha">
<?php
$rs = mysql_query("SELECT * FROM ti_linhas ORDER BY nm_linha");
while($reg = mysql_fetch_object($rs)): ?>
<option value="<?php echo $reg->cd_linha ?>"><?php echo $reg->nm_linha ?></option>
<?php endwhile; ?>
</select>
<br /><br />
<div id="familia"></div>
</body>
</html>
listaFamilias.php
<?php
include '../url_seo.php';
include 'config/config.inc.php';
include "funcoes/conexao.php";
conecta();
$cd_linha = $_GET['cd_linha'];
$rs = mysql_query("SELECT * FROM ti_familias WHERE cd_linha = '$cd_linha' ORDER BY nm_familia");
echo "<label>familias: </label><select name='familia'>";
while($reg = mysql_fetch_object($rs)){
echo "<option value='$reg->cd_familia'>$reg->nm_familia</option>";
}
echo "</select>";
How do I make the combobox that is listed in Friends.php already filled with database data?
$('#familia').load
will attempt to place a new select inside your select, which is invalid. You will need to create an element outside of select to use .load. Or in php to send only options.– bfavaretto
Thanks for the reply @bfavaretto, but I didn’t understand.
– Danny Dantas