Autocomplete with addtional parameters

Autocomplete with addtional parameters

Dear Sir

In a registration form Auto complete is working fine


 I am accepting
First Name *
After this I am accepting following 3 fields 
Father's Name  Auto Suggest based on name accepted-Name+ value entered
Grand Father's Name Auto Suggest based on name accepted Name, Father's Name + value entered
Great Grand Father's Name Auto Suggest based on name accepted Name, Father's Name, Grand Father's Name + value entered

 For each auto complete I am using following script 
(by changing appropriate values as per field and name of program called)

  1. $("#fathersname").autocomplete({
  2.  source: "kvmasterdata_fathersnamesearch.php",
  3.  
  4. minLength: 2,
  5. select: function(event, ui) {
  6. var getUrl = ui.item.id;
  7. if(getUrl != '#') {
  8. location.href = getUrl;
  9. }
  10. },
  11.  
  12. html: true,
  13.  
  14. open: function(event, ui) {
  15. $(".ui-autocomplete").css("z-index", 1000);
  16. }
  17. });
In this case what I want is

when I accept father's name (only after accepting the name i.e First Name )
I want to pass (the accepted) name as an additional parameter (for auto suggest values to be displayed)
so that my query will be

$query = 'SELECT distinct bg.name  FROM kvmasterdata bg WHERE bg.name LIKE "%'.$user_input.'%"
 and name='.$user_name ;

and NOT 

$query = 'SELECT distinct bg.name  FROM kvmasterdata bg WHERE bg.name LIKE "%'.$user_input.'%"';


Note : 
where $user_name = value accepted in following field
First Name *


Please help