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>