Pass ComboBox to Input

0

I have a ComboBox that when I select it I want to pass the data to Input

That is, what I want to achieve, is when you select the Select this in turn paint in Input the data that corresponds to the query you are making to BBDD

código es

Iniciador of ComboBox

                <th style="text-align:left;">Código del pedido</th>
            <td>
              <select  style="width:218%" class="form-control" name="codigo" id="codigo" onchange="change_documento();  change_documento1(); change_documento2(); change_documento3(); change_documento4(); change_documento5()" required>
                <option value=""><?php echo isset($obj_categoria) ? $obj_categoria->__GET('codigo') : ''; ?> </option>    
                <?php
                $pdo = new PDO('mysql:host=localhost;dbname=prueba', 'prueba', 'prueba');
                $pdo->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
                $stmt = $pdo->prepare('Select distinct puo from puo order by puo');
                $stmt->execute();
                while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                  ?>
                  echo <option value="<?php echo $row['puo']; ?>"><?php echo $row['puo']; ?> </option>
                  <?php }
                  ?>

                </select> 
              </td>

Function JavaScript

   function change_documento()
{
var codigo = $("#codigo").val();

$.ajax({
  type: "POST",
  url: "subcategoria.php",
  data: "codigo=" + codigo,
  cache: false,
  success: function (response)
  {
                      //alert(response);return false;
                      $("#producto_servicio1").html(response);
                    }
                  });
}

File subcategoria.php

<?php
include('dbConfig.php');
$codigo = $_POST['codigo'];
$sql= "select producto_servicio from puo where puo='$codigo' order by producto_servicio";
$query = $db->query($sql);

while($res = $query->fetch_assoc()){
echo '<option  value="'.$res['producto_servicio'].'">'.$res['producto_servicio'].'</option>'  ; 
}

?>

% co_of% that receives the data

     <th style="text-align:left;">Nombre del Pedido</th>
        <td>
           <input type="text" style="width:218%" class="form-control" name="producto_servicio1" id="producto_servicio1" disabled onchange="change_documento();"
                  value="<?php echo isset($obj_categoria) ? $obj_categoria->__GET('producto_servicio1') : ''; ?>" />
            </td>
    
asked by Alberto Cepero de Andrés 16.08.2017 в 13:14
source

1 answer

2

In the subcategory.php

    <?php
    include('dbConfig.php');
    $codigo = $_POST['codigo'];
    $sql= "select producto_servicio from puo where puo='$codigo' order by producto_servicio";
    $query = $db->query($sql);

    while($res = $query->fetch_assoc()){
    echo $res['producto_servicio']; 
    }

    ?>

In your JavaScript

   function change_documento()
{
var codigo = $("#codigo select").val();

$.ajax({
  type: "POST",
  url: "subcategoria.php",
  data: {codigo:codigo},
  cache: false,
  success: function (response)
  {
                      //alert(response);return false;
                      $("#producto_servicio1").val(response);
                    }
                  });
}

Input that receives the data

  

Here I honestly do not know what you want to do in the value but with   Leave it empty. The onchange function would not need it since it is   called by the ComboBox

<th style="text-align:left;">Nombre del Pedido</th>
    <td>
       <input type="text" style="width:218%" class="form-control" name="producto_servicio1" id="producto_servicio1" disabled
              value="" />
        </td>
    
answered by 16.08.2017 / 14:03
source