How to fill in the full form input fields from the database based on the value selected from the drop-down list
Example. In the application, choosing the name of the client, he fills in the input field of the form with the data stored in the database.
Sample Code:
<select name="client">
<option value="">-- Select Client Name -- </option>
<option value="1">John</option>
<option value="2">Smith</option>
</select>
<input name="phone" type="text" value="">
<input name="email" type="text" value="">
<input name="city" type="text" value="">
<textarea name="address"></textarea>
All input fields must be filled with values to select a client name.
EDIT:
I tried with AJAX but could not get the specific variable from the file ... below is my code:
<script>
$(document).ready(function() {
$('#client').change(function() {
alert();
var selected = $(this).find(':selected').html();
$.post('get_details.php', {'client': selected}, function(data) {
$('#result').html(data);
});
});
});
</script>
In the file get_details.phpI store different values in different variables, but I did not understand how to transfer them to a separate variable on the main page.
source
share