I have a family tree and dropdown also has all name of parent and child, inside each child there is link, i want when i clicked on any child link displayed his father in dropdown (make it option selected). Please someone help me.
this is function to display the child
function getChild($family_tree,$parent){
$list = "<ul style='list-style-type:none'>";
foreach($family_tree[$parent] as $each_child){
$list .= "<li>" . $each_child[0]." "."<a style='text-decoration:none ; font-size: smaller' onclick='changeParent()' href='#'>".'Change parent'."</a>";
if(isset($family_tree[$each_child[1]])){
$list .= getChild($family_tree,$each_child[1]);
}
$list .= "</li>";
}
$list .= "</ul>";
return $list;
}
and this function to get the father of child
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 is my form
<form method="post">
Child Name: <input type ='text' name ='name' placeholder="Enter name here">
<select name="parent" id="names" onchange="getSelectValueId()">
<option>--Select Parent--</option>
<option><?php echo $object->displayParent()?></option>
</select>
<br>
<input type="submit" name="submit" value="Enter">
</form>
Update **** Now i get the child id when i clicked on link and i has function that get parent id ... how i can change the option selected now ?? any one can help me plz !!!!
this is the function gets the id of child from link
function changeParent(){
$(document).ready(function(){
$("a").click(function() {
function getEventTarget(e) {
e = e || window.event;
return e.target || e.srcElement;
}
var ul = document.getElementsByClassName('listSet');
[].forEach.call(ul, function(el) {
el.onclick = function(event) {
var target = getEventTarget(event);
alert(target.id);
};
});
});
});
}
</div>