El código completo es
$('#subcategorias').attr('disabled','disabled');
$('#zonas').attr('disabled','disabled');
$("#categorias").change(function () {
$("#categorias option:selected").each(function () {
var v_elegido=$(this).val();
$('#subcategorias').removeAttr('disabled');
if($(this).val() == "Departamentos") {
$('#zonas').removeAttr('disabled');
} else {
$('#zonas').attr('disabled','disabled');
}
$.post("subcategorias.php", { elegido: v_elegido }, function(data){
$("#subcategorias").html(data);
});
});
Cuando habilito departamentos desde categorías debería habilitarse zonas (con las subcategorias no tengo problemas)
Código PHP:
<?php if ($campo == 'zonas') { ?>
<div class="col_texto" align="right"><?php echo $campo ?>: </div>
<div id="varietal" style="visibility:visible;">
<select name="zonas" id="zonas">
<option value="0">-</option>
<?php
$conn = DataBase::getInstance();
$rel=false;
$relacion='_'.$campo;
$conn->setQuery('SELECT * FROM `_'.$campo.'` ORDER BY id ASC');
if ($conn->len()==0){
$rel=true;
$relacion=$campo;
$conn->setQuery('SELECT * FROM `'.$campo.'` ORDER BY id ASC');
}
if ($conn->len()==0){
$rel=true;
$relacion=$campo.'s';
$conn->setQuery('SELECT * FROM `'.$campo.'s` ORDER BY id ASC');
}
if ($conn->len()>0){
$rs = $conn->loadObjectList();
foreach($rs as $valor){?>
<option value="<?php echo $valor->id ?>"><?php echo $valor->titulo ?></option>
<?php
}}?>
</select>
</div>
<?php } else { ?>
<?php if ($campo == 'subcategorias') { ?>
<div class="col_texto" align="right"><?php echo $campo ?>: </div>
<div>
<select name="<?php echo $campo ?>" id="<?php echo $campo ?>">
<option value="0">-</option>
<?php
$conn = DataBase::getInstance();
$rel=false;
$relacion='_'.$campo;
$conn->setQuery('SELECT * FROM `_'.$campo.'` ORDER BY id ASC');
if ($conn->len()==0){
$rel=true;
$relacion=$campo;
$conn->setQuery('SELECT * FROM `'.$campo.'` ORDER BY id ASC');
}
if ($conn->len()==0){
$rel=true;
$relacion=$campo.'s';
$conn->setQuery('SELECT * FROM `'.$campo.'s` ORDER BY id ASC');
}
if ($conn->len()>0){
$rs = $conn->loadObjectList();
foreach($rs as $valor){?>
<option value="<?php echo $valor->id ?>"><?php echo $valor->titulo ?></option>
<?php
}}?>
</select>
</div>
<?php } else { ?>
<div class="col_texto" align="right"><?php echo $campo ?>: </div>
<div>
<select name="categorias" id="categorias">
<option value="0">-</option>
<?php
$conn = DataBase::getInstance();
$rel=false;
$relacion='_'.$campo;
$conn->setQuery('SELECT * FROM `_'.$campo.'` ORDER BY id ASC');
if ($conn->len()==0){
$rel=true;
$relacion=$campo;
$conn->setQuery('SELECT * FROM `'.$campo.'` ORDER BY id ASC');
}
if ($conn->len()==0){
$rel=true;
$relacion=$campo.'s';
$conn->setQuery('SELECT * FROM `'.$campo.'s` ORDER BY id ASC');
}
if ($conn->len()>0){
$rs = $conn->loadObjectList();
foreach($rs as $valor){?>
<option value="<?php echo $valor->id ?>"><?php echo $valor->titulo ?></option>
<?php
}}?>
</select>
</div>