I have one ComboBox
that when I select it I want it to pass the data to aInput
That is to say, what I want to achieve, is when you select Select
it, paint in turn Input
the data that corresponds to it from the query you are making to theBBDD
Thecódigo es
Iniciador
ofComboBox
<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>
FunctionJavaScript
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, Archivesubcategoria.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>' ;
}
?>
Input
who 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>
In the subcategory.php
in your javascript
Input that receives the data