title: Insert variables into a URL
body: <p>I'm trying to add a "share" feature to (my own) Google Chrome Extension but I've stumbled across issues with variables and URLs (I'm useless when it comes to JavaScript).</p>
  
  <p>My code is below, if anyone could guide me in where to go I would be heavily grateful.</p>
  
  <pre><code>&lt;script&gt;
      chrome.tabs.getSelected(null, function(tab) {
          document.getElementById('longLink').value = tab.url;
        });
        var shareURL = document.getElementById('longLink')
  &lt;/script&gt;
  &lt;a href="https://twitter.com/?status=" + shareURL + "&amp;choe=UTF-8" target="_blank"&gt;Tweet This&lt;/a&gt;
  </code></pre>
  
  <p><em>I've also tried</em></p>
  
  <pre><code>&lt;a href="https://twitter.com/?status=" + encodeURIComponent(shareURL); + "&amp;choe=UTF-8" target="_blank"&gt;Tweet This&lt;/a&gt; 
  </code></pre>
  
  <p>Finally, I tried this method</p>
  
  <pre><code>&lt;script&gt;
    function tweet() {
      var twitter='http://twitter.com/?status='+encodeURIComponent(tab.url);
      chrome.tabs.create({url: twitter});
    }
  &lt;/script&gt;
  &lt;a onClick="tweet()" href="" target="_blank"&gt;Tweet&lt;/a&gt;
  </code></pre>