title: Passing variable from a function to a function within a function
body: <p>I'm trying to create a chrome extension that takes a selected text via context menu, appends it to a url and update an existing tab (from the same domain) with the new URL.
  This is my code:</p>
  
  <pre><code>function soso(search_target){
      alert(search_target);
      //search_target gets here successfully 
  
      chrome.tabs.query({
          url: "https://lightning.force.com/lightning/*"},
          function(tabs, search_target){
  
          if (tabs[0]){
  
              chrome.tabs.update(tabs[0].id, {
                  url: "http://www.facebook.com"+search_target, //search_target doesnt get here
                  active: true
              });
          }
          else{
              alert("no window");
          }
          });
  }
  
  
  function selectionHandler (info, tab)
  {
          soso( info.selectionText);
  }
  
  function resetContextMenus ()
  {
      chrome.contextMenus.removeAll(
      function()
      {
              var id = chrome.contextMenus.create( {
                  title: "Open in Salesforce",
                  contexts: [ "selection" ],
              onclick: selectionHandler
          } );
      }
      );
  }
  resetContextMenus();
  </code></pre>
  
  <p>The problem is that I cannot pass <code>search_target</code> to <code>chrome.tabs.update</code>, I get an <code>undefined</code> after the URL.</p>
  
  <p>Any ideas on how to pass this variable?</p>