2

Tengo el siguiente formulario introducir la descripción de la imagen aquí

A continuación el código que tengo hasta ahora:

    <select onchange="cargarDocumento()" name="c_almacen">
      <option selected="selected" value = '0'></option>
      <?php
         while ( $registro=ifx_fetch_row($g_idq)  )
         {
           echo '<option value = '.$registro['c_almacen'].'>'.$registro['c_almacen']." -- ".$registro['d_almacen'].'</option>';  
         }
      ?>
    </select></td>
  <td width="247"><div  id="contenedorDocumento"><div class="Estilo2">Debe seleccionar un almac&eacute;n</div></div></td>
  </tr>
</table>
<table width="625">
     <tr>
       <td width="156">&nbsp;</td>
       <td width="58"><input type="button" onclick="ejecutar('D')" name="diferencias" value="DIFERENCIAS" /></td>
       <td width="89"><input type="button" disabled onclick="ejecutar('A')" name="ajustar" value="AJUSTAR" /></td>

En la parte de seleccionar el almacén se habilita la opción para salir el documento con la función contenedorDocumento

function cargarDocumento()
    { 
        var conce,contenedor; 

            contenedor = document.getElementById("contenedorDocumento"); 
            c_almac = eval("document.form1.c_almacen.options[document.form1.c_almacen.selectedIndex].value");
            ajax=nuevoAjax(); 

        ajax.open("POST","ajax_documento_teo.php",true); 

        ajax.onreadystatechange=function() 

//se ejecuta el ajx del documento_teo.php

$c_almace =$_POST['c_alm'];

?>
<td>
        <?php
         $sql = "SELECT UNIQUE(cs_teorico) documento FROM h_inventario_teo WHERE c_almacen = ".$c_almace." AND (estado = 'P' OR estado = 'D')";

         p_query($sql);
         //echo "--1-<br> $sql <br><br>";
        ?>
        Documento: <select name="documento">
        <option value = ''></option> 
        <?php

         while ( $registro=ifx_fetch_row($g_idq)  )
          {
           echo '<option value = '.$registro['documento'].'>'.$registro['documento'].'</option>';  
          }

        ?>
        </select></td>

No sé como hacer que el botón de ajustar solo se habilite cuando el estado del documento está en estado P.

2 respuestas 2

1

Itera tus documentos y en el value del option guarda el estado.

// usando mysqli
while($documento -> $query->fetch_assoc()) {
    <option value="<?= $documento->estado; ?>" onChange="onDocSeleccionado(this)">
        <?= documento->nombre;?>
    </option>
<=php } ?>

Fíjate que le hemos asociado una función en cuanto se seleccione un ítem. En esa función se obtiene el valor seleccionado y se comprueba la condición. Si la cumple se activa el botón.

function onDocSeleccionado(e) {
  if(e.value === 'P') {
    document.getElementById('btn-ajustar').removeAttribute('disabled');
}
0

En las funciones ejecutar o donde pueda cambiar el estado se puede llamar a otra función habilitarControles

function habilitarControles(){
    document.getElementById("ajustar").disabled = estado!='P';
}

hay que ponerle el id a los botones (o cambiar getElementById por getElementsByName y buscar el primero)

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.