my function can't pass it's parameter value javascript
<p>Ive been struggling to pass my parameters from a functions but I just really can't figure out where did I go wrong. I have a function that have a parameters that I want to pass to my postData to display datas in my jQgrid. Here's my function code with parameters:</p>

<pre><code>function getTID(hdrID){
  var selected = $('#editTallyHdr').val();  
  var hdrID = '';
  var hdrNo = '';

  var nameFlag=0;
  var par_ams = {
    "SessionID": $.cookie("SessionID"),
    "dataType": "data"
  };
  $.ajax({
    type: 'GET',
    url: 'processjson.php?' + $.param({path:'getData/tallyHdr',json:JSON.stringify(par_ams)}),
    dataType: primeSettings.ajaxDataType,
    success: function(data) {
      if ('error' in data)
      {
        showMessage('ERROR: ' + data["error"]["msg"]);
      }
      else{            
        $.each(data['result']['main']['rowdata'], function(rowIndex, rowDataValue) {
          $.each(rowDataValue, function(columnIndex, rowArrayValue) {
            var fldName = data['result']['main']['metadata']['fields'][columnIndex].name;
            if (fldName == 'transaction_id'){
              hdrID = rowArrayValue; 
            }
            if (fldName == 'transaction_num'){   
              hdrNo = rowArrayValue; 
              if(selected == hdrNo){
                nameFlag =1;
              };        
            }
          });   
        }); 
      }
    }
  }); 
  return (hdrID);
} 
</code></pre>

<p>and here is my jQgrid code where I call that function to get it's parameter:</p>

<pre><code>$("#tblPlank").jqGrid({
        url: '',                            
        datatype: 'local',
        jsonReader : {
          .
          .
          .
serializeGridData: function(postData) {

      var ctr =0;
      var filt=[];
      var c=[];      

      var jsonParams = {
      'SessionID':  $.cookie("SessionID"),
      'dataType': 'data',
      'transaction_id':getTID(hdrID),
      'filters': c,
      'lines':plank_data,      
      'recordLimit': postData.rows,
      'recordOffset': postData.rows * (postData.page - 1),
      'rowDataAsObjects': false,
      'queryRowCount': true,
      'sort_fields': postData.sidx
      };  
.
.// some code here
.
. 
      return 'json=' + JSON.stringify(jsonParams);
    },
    loadError: function(xhr, msg, e) { 
      showMessage('HTTP error: ' + JSON.stringify(msg) + '.');
    },
    colNames:[...], 
    colModel:[      
     ........................
    ],  
    .
    .
    .
    caption: "Tally Transaction Details/Lines"
</code></pre>

<p>I also have another code where I want to get that parameter. Here's the last code:</p>

<pre><code>var par_ams = {
    "SessionID": $.cookie("SessionID"),
    "dataType": "data",
    "transaction_id": getTID(hdrTID) 
}                                              
$('#tblPlank').setGridParam({
    url:'processjson.php?path=' + encodeURI('getData/tallyLnDtl') + '&amp;json=' + encodeURI(JSON.stringify(par_ams)), 
    datatype: primeSettings.ajaxDataType,  
});
$('#tblPlank').trigger('reloadGrid');      
</code></pre>

<p>Those codes below that function getTID(hdrID) cant retrieve the parameter, it shows empty. This maybe simple to anyone, but I really need help on this.. been working with this for quite long hours.</p>
