I have list like this
John
Jack
Husam
Koko
Rami
Loay
And i have dropdown list its also has all this names, when i entered the id of Rami for example in URL he make it selected option in dropdown list, i want if i entered the id of Rami in URL make his parent (Koko) selected option not Rami. I build function to get parent id and its work How can i call it from ajax and get parent id of the id i input it in URL
php
public function getParentId($childId)
{
$statment = $this->db->prepare("SELECT parent FROM `person` WHERE id = $childId");
$statment->execute();
$result = $statment->fetchAll();
foreach($result as $output){
return $output['parent'];
}
}
And this my ajax
if ($object->getParentId(($_GET['childId']))){
echo "<script>
$(document).ready(function(){
$.ajax({
type: 'GET',
url: 'http://test.local/Family.php?action=getId&childId=idd',
data: {'idd' : $_GET[childId]},
success: function(msg) {
document.getElementById('names').value = $_GET[childId];
}
});
}); </script>";
}