So i can populate the dropdown with information from the database, however i what i need to be done is when i click on a option in the dropdown, it should display the email of that selected option in a textbox. So in essence, select dropdown, select company and then it pulls the information (email) from the database and inserts it into a textbox
Please help?
PHP / HTML PAGE
<div class="customerInfo">
<div class="blockSelect">
<div class="select" style="margin-right: 5px;">
<select name="cat" id="cat">
<option value="" disabled selected>Customer</option>
<?php
$records = mysqli_query($conn, "SELECT company FROM clients");
while($data = mysqli_fetch_array($records))
{
echo "<option value='". $data['company'] ."'>" .$data['company'] ."</option>"; // displaying data in option menu
}
?>
</select>
<?php mysqli_close($conn); // close connection ?>
</div>
</div>
<div class="blockSelect">
<input type="text" name="mail" id="mail" style="color: black; border-bottom: 1px solid;">
</div>
</div>
AJAX CODE
$('#cat').change(function(){
var package = $(this).val();
$.ajax({
type:'POST',
data:{package:package},
url:'get_details.php',
success:function(data){
$('#mail').val(data);
}
});
get_details.php
<?php
include("server.php");
if (isset($_POST['package'])) {
$qry = "SELECT * FROM clients WHERE company=" . $_POST['package'];
$rec = mysql_query($qry);
if (mysql_num_rows($rec) > 0) {
while ($res = mysql_fetch_array($rec)) {
echo $res['email'];
}
}
die();
}
?>