HTML and PHP
<?php for($i=0;$i<2;$i++) { ?>
<select id="name_<?php echo $i;?>">
<option value="John">John</option>
<option value="Alice">Alice</option>
</select>
<input type="text" id="name-id_<?php echo $i;?>">
<input type="text" id="location_<?php echo $i;?>">
<?php } ?>
JS
for (var i = 0; i < 2; i++)
{
$('select#name_'+i).on('change',function()
{
name = $('select#name_'+i).val();
if($.trim(name) !='')
{
$.post('ajax/name.php',{name:name},function(data)
{
$('input#name-id_'+i).val(data);
});
$.post('ajax/location.php',{name:name},function(data)
{
$('input#location_'+i).val(data);
});
}
});
}
ajax/name.php and ajax/location.php are the files that retrieve data from DB. The output that I want is the data will appear in the name and location column according to the drop down menu data that I chose.