title: How to access a Javascript variable from Table data in HTML?
body: <p>I have the following Javascript and want to access the "selection" variable in my HTML's td which already has an id</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;  
  function getSelected() {
      if(window.getSelection) { return window.getSelection(); }
      else if(document.getSelection) { return document.getSelection(); }
      else {
              var selection = document.selection &amp;&amp; document.selection.createRange();
              if(selection.text) { return selection.text; }
              return false;
      }
      return false;
  }
  
  $(document).ready(function() {
      $('#content-area').mouseup(function() {
              var selection = getSelected();
              if(selection &amp;&amp; (selection = new String(selection).replace(/^\s+|\s+$/g,''))) {
              alert('Sending the following text to the server via AJAX: ' + selection);
                      $.ajax({
                              type: 'post',
                              url: 'calculate.php',
                              data: 'selection=' + encodeURI(selection)
                      });
              }
    });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>The place I want to access "selection" variable is the html's td as follows,  </p>
  
  <pre><code>&lt;td&gt;
  &lt;input type="button" id="optionone" name="optionone" onclick="sendrequest(selection , &lt;?php echo $r ?&gt;);" value="Positive"/&gt;
  &lt;/td&gt;  
  </code></pre>
  
  <p>I tried using id(content-area) but of no help. Please help.</p>