Enable Input According to a select PHP SQL - SERVER

0

Cordial Greeting.

I hope you can help me with the problem I have, or an idea of how to achieve what I want.

I tell you what I want to do:

  • I have a Select PHP - SQL: Contains in the database: Id, Name, Field1, Field2, Field3, Field4, Field5
  • Each Field1 to Field5, Contains an SI Value or a NO value.

    2. The select will be loaded: Example:

    <select>
    <option>Seleccionar</option>
    <option>Prueba</option>
    </select>
    

    The test field is the one in the database, and contains the Id, Name, Field1, Field2, Field3, Field4, Field5.

  • I have 5 Inputs.
  • What I want to do is if by selecting "Test" in the SELECT, I activate the input 1, if it has a value of "YES", If you do not have yes, the input should be disabled.

    It is the same dynamic with the other inputs.

    I do not know how to do it, I hope you can help me and I hope you understood me.

    Thus I charge the Select:

     <?php
                        include'conexion.php';
    
                        $sql = "EXEC SP_COMBO_PAGADURIAS";
                        $stmt = sqlsrv_prepare($conn, $sql);
                        if(sqlsrv_execute($stmt)){
                        $menu="<select name='menu' onchange='getComboC(this)' class='form-control' id ='menu'>\n<option selected>Seleccionar:</option>";
                        while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)){
                        $menu.="\n<option value='".$row['Campo1']."'>".utf8_encode($row['Nombre'])."</option>";
                        }
                        $menu.="\n</select>";
                        echo $menu;
                        }
                    ?>
    

    Inputs:

     <?php
    
      for ($i=0; $i<=5; $i++){
      switch ($i){
    
        case 0:
    
          $pos = strpos($row, 'SI');
    
    
            if($pos !== false ){
    
                 echo '<input type="text" class="form-control" name="uno" id="uno">';
    
          }else{
    
    
    
                 echo '<input type="text" class="form-control" disabled name="uno" id="uno">';
    
          }
    
          break;
    
    
        case 1:
    
         $pos = strpos($Acceso, 'F');
    
            if($pos !== false ){
    
                 echo '<input type="text" class="form-control" name="uno" id="uno">';
    
          }else{
    
                 echo '<input type="text" disabled class="form-control" name="uno" id="uno">';
    
          }
    
    
          break;
    
       case 2:
    
        $pos = strpos($Acceso, 'R');
    
            if($pos !== false ){
    
                 echo '<input type="text" class="form-control" name="uno" id="uno">';
    
          }else{
    
                 echo '<input type="text" disabled class="form-control" name="uno" id="uno">';
    
           }
    
    
          break;
    
    
       case 3:
        $pos = strpos($Acceso, 'N');
    
           if($pos !== false ){
    
                 echo '<input type="text" class="form-control" name="uno" id="uno">';
    
         }else{
    
                 echo '<input type="text" disabled class="form-control" name="uno" id="uno">';
    
         }
    
        break;
    
          case 4:
        $pos = strpos($Acceso, 'N');
    
           if($pos !== false ){
    
                 echo '<input type="text" class="form-control" name="uno" id="uno">';
    
         }else{
    
                 echo '<input type="text" disabled class="form-control" name="uno" id="uno">';
    
         }
    
         break;
    
         case 5:
        $pos = strpos($Acceso, 'N');
    
           if($pos !== false ){
    
                 echo '<input type="text" class="form-control" name="uno" id="uno">';
    
         }else{
    
    
                 echo '<input type="text" disabled class="form-control" name="uno" id="uno">';
    
         }
    
    
    
    
    } 
    
     }
    
    
    ?> 
    
        
    asked by Andres Rodriguez 09.10.2018 в 15:53
    source

    1 answer

    0

    What you want is that when you select "test" you see the 5 input and that only those that say yes are editable. - Good

    Here I leave a php. If you do not understand decime.

    $sql = "SELECT * FROM prueba";
        $result = $conn->query($sql);
             while($row = $result->fetch_array(MYSQLI_ASSOC)){
    $campo1 = $row['campo1'];
    $campo2 = $row['campo2'];
    $campo3 = $row['campo3'];
    $campo4 = $row['campo4'];
    $campo5 = $row['campo5'];
    
    if($campo1 == 'si'){
        echo '<script>document.getElementById("input1").readonly = false;'
    }
    if($campo2 == 'si'){
        echo '<script>document.getElementById("input2").readonly = false;'
    }if($campo3 == 'si'){
        echo '<script>document.getElementById("input3").readonly = false;'
    }if($campo4 == 'si'){
        echo '<script>document.getElementById("input4").readonly = false;'
    }if($campo5 == 'si'){
        echo '<script>document.getElementById("input5").readonly = false;'
    }
    

    }

        
    answered by 09.10.2018 в 16:03