0

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>";
 }
1
  • 2
    bobby-tables.com learn about SQL injection first. Commented Jun 13, 2018 at 8:47

1 Answer 1

1

I change this part

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>";
 }

To this and its work

if ($object->getParentId(($_GET['childId']))){
echo "<script>
$(document).ready(function(){
$.ajax({
type: 'GET', 
url: 'http://test.local/Family.php?action=getId',
data: {'childId' : $_GET[childId]},
success: function(msg) {
document.getElementById('names').value = msg;
}
});
}); </script>";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.