0
Hello! I have some clients registered in the database, the client’s choice is made through a form select that returns the data to me in another form select. I would like to return the data in different and separate input type. Address type in one input, neighborhood in another and so on. Someone could direct me as I do?
<?php
require_once ("DBController.php");
$db_handle = new DBController();
$query = "SELECT * FROM clientes";
$clienteResult = $db_handle->runQuery($query);
?>
<html>
<head>
<TITLE>Retornar dados nos input</TITLE>
<head>
<style>
body {
width: 610px;
font-family: calibri;
}
.form-DronpDown {
border: 1px solid #7ddaff;
background-color: #C8EEFD;
margin: 2px 0px;
padding: 40px;
border-radius: 4px;
}
.form-control {
padding: 10px;
border: #bdbdbd 1px solid;
border-radius: 4px;
background-color: #FFF;
width: 50%;
}
.row {
padding-bottom: 15px;
}
</style>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" type="text/javascript"></script>
<script>
function getdados() {
var str='';
var val=document.getElementById('cliente-list');
for (i=0;i< val.length;i++) {
if(val[i].selected){
str += val[i].value + ',';
}
}
var str=str.slice(0,str.length -1);
$.ajax({
type: "GET",
url: "get_dados.php",
data:'clienteID='+str,
success: function(data){
$("#dados-list").html(data);
}
});
}
</script>
</head>
<body>
<div class="form-DronpDown">
<div class="row">
<label>cliente:</label><br />
<select name="cliente[]" id="cliente-list" class="form-control" onChange="getdados();" >
<option value="">Select cliente</option>
<?php
foreach ($clienteResult as $cliente) {
?>
<option value="<?php echo $cliente["id"]; ?>"><?php echo $cliente["cliente_name"]; ?></option>
<?php
}
?>
</select>
</div>
<div class="row">
<label>Dados:</label><br />
<div name="dados[]" id="dados-list" class="form-control" size=5></div>
</div>
</div>
</body>
</html>