Hello good day everyone I have a database that has 3 columns [id] [customer] [price] the customer data is loaded in a select and I would like that when selecting the customer in the select the price data is loaded in an input
first of all, Thanks
// Cada vez que cambie el select
$("#seleccionarCliente").change(function(){
// a la variable x le asigno el value del select con id="seleccionarCliente"
var x = $('#seleccionarCliente').val();
// le asigno el valor de x al input con id="cdCliente"
$('#cdCliente').val(x);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-users"></i></span>
<select class="form-control" id="seleccionarCliente" name="seleccionarCliente" required>
<option value="">Seleccionar cliente</option>
<!--Ejemplos para mostrar el resultado, los puedes eliminar-->
<option value="1">Cliente 1</option>
<option value="2">Cliente 2</option>
<?php
$item = null;
$valor = null;
$categorias = ControladorClientes::ctrMostrarClientes($item, $valor);
foreach ($categorias as $key => $value) :?>
<option value="<?= $value['id']; ?>"><?= $value['nombre']; ?></option>
<?php endforeach;
?>
</select>
<!-- cambiar type text por hidden -->
<input type="text" id="cdCliente" name="cdCliente" >
</div>
</div>
This is the code that I had originally but I need to get the price column from the database and place it in the input id="cdCliente" when selecting the client in the option
To clarify, I don't work in php, but if I have experience in ajax and jquery, if what you want is to leave one of the data in an input, you have to do it in the following way.
this is an example made in java but add the line of how to set a value in the input.
greetings