JavaScript Function Return Scope
<p>A function triggers a database call which returns some Json. This CID is then used to stamp the newly added DOM element.</p>

<p>I need to retrieve / return the value of "cid" which exists within ajax success block, it will be used to update attribute.</p>

<p>Error
<strong>cid is not defined</strong></p>

<pre><code>//Save New Task
$("body").on('click','.icon-facetime-video',function(event){
  var new_entry = $(this).prev().val();
  var thebid = $(this).parents('tbody').prev().find('th').attr('id').split('_')[1];
  $(this).parent().addClass('tk').html('&lt;i class="icon-eye-open"&gt;&lt;/i&gt; '+new_entry);
  //CALL FUNCTION
  var cid = update_entry('new_tk',new_entry,thebid); //value of cid from update_entry
  $(this).parent().attr('id','cid_'+cid);
});

function update_entry(typeofupdate,new_entry,thebid){

  switch(typeofupdate){
    case 'new_tk': var action = 'new_tk';
    break;
  }

  $.ajax({
        type:'post',
        url: 'posts_in.php',
        dataType: "json",
        data: {cid : thebid, action: action, content: new_entry},
        success: function(data){
            var action = data[0],cid= data[1];
            console.dir(data);
        }
    });

  return cid;  
}
</code></pre>
