Wat till earlier Jquery is executed

Wat till earlier Jquery is executed

Dear All

I have 2  div' (refer  http://jsfiddle.net/6evD2/8/ as a sample pls note they are not functioning)

From one div  i am allowing user to select headers using autosuggestion ( let us call this  All Div Header)
and other div had    headers aleady allocated or selected by user
 (let us call it Selected  Header  Div)

In short user selects an header from All Div Header (as well as database table)
and after clicking Add
and that header is transferred to   Selected Header Div( as well as database table)


I am allowing user to select  header using 'autosuggestion'

Suppose the All Div header has only one  value  Cat (only one row)
and user types Dog (suggestion will show zero or no records)

In this case when Add is clicked
It should get added in both these div's and database  tables

All Div Header 
Selected Header Div

Which is happening no issues here

What i want is 

In case the header is new (like specified above when user types Dog and clicks add)

I Want to add new header box to appear

If user types Cat ( The name exists) and clicks Add
the the header will get added  (in  Selected Header Div ) without asking

I had written following JQUERY; 

  1. $("#addheader").click(function () { // user had selected header and click Add button to add this header in
  2. $('#findheaderiddiv').empty(); // storing number of rows from 
    All Div Header using JQERY
  3.     
  4.   var url = "findheaderid.php" // JQUERY program to find number of rows in All Div Header using
  5.   var data = { 
  6.     keyword:  $('#keyword').val() // complete string (typed by user )is passed
  7.   };
  8.   $('#findheaderiddiv').load(url, data, Headeradd()); // I want to call  function
     Headeradd() after i get  output of findheaderid.php  buy it seems it is called before completion of findheaderid.php Pls help
  9. });
  10. function Headeradd() {// to be called after 
    $('#findheaderiddiv').load(url, data) is over
  11.  var hid=$('#findheaderiddiv').text(); //  get value store in line number 8 and store in variable hid 
  12.   
  13. if (hid>=1)  // I am unable to fetch this value it seems 
     Headeradd() in line no 8 is not called after completion of  
  14. {alert("header exists");
  15. $('#findheaderiddiv').empty();
  16. // JQUERY to add this header in Selected Header Div 
  17. }
  18. else
  19. {  var url = "updateheader.php"
  20.   var data = { 
  21.     keyword: $('#keyword').val(), 
  22.     recordid: $('#recordid').val()
  23.   };
  24.   $('#selectheaderdiv').load(url, data) ;// new header and hence update it in both Tables and Div's this program working OK 

  25. $('#findheaderiddiv').empty();
  26. }
  27. }