title: Use script from inside an array
body: <p>I'm trying to assign a key to each cell of a user-generated table with unknown amounts of columns and rows: </p>
  
  <p>e.g., HTML</p>
  
  <pre><code>    &lt;table&gt;
       &lt;tr&gt;
        &lt;td&gt;
         &lt;select class="colheaders"&gt;
          &lt;option value="firstname"&gt; first name&lt;/option&gt;
          &lt;option value="familyname"&gt; Family name&lt;/option&gt;
         &lt;/select&gt;
       &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
       &lt;td&gt;
        &lt;select class="colheaders"&gt;
         &lt;option value="firstname"&gt; first name&lt;/option&gt;
         &lt;option value="familyname"&gt; Family name&lt;/option&gt;
        &lt;/select&gt;    
       &lt;/td&gt;
     &lt;/tr&gt;
  
     &lt;tr&gt;
      &lt;td&gt;Bob&lt;/td&gt;
      &lt;td&gt;Smith&lt;/td&gt;
     &lt;/tr&gt;
  
    &lt;tr&gt;
      &lt;td&gt;John&lt;/td&gt;
      &lt;td&gt;Jones&lt;/td&gt;
     &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Instead of this</p>
  
  <pre><code>$('#mytable tr').each(function(row, tr) {
      TableData[row] = {
          "col1": $(tr).find('td:eq(1)').text(), 
          "col2": $(tr).find('td:eq(2)').text(), 
          "col3": $(tr).find('td:eq(3)').text()
      }
  });
  </code></pre>
  
  <p>"col1" would be the selected option from the same row. Once Posted via AJAX I would be able to return a key->value array.</p>
  
  <p>e.g.,</p>
  
  <pre><code>{
   "first name" : "bob",
   "family name" : "smith"
  }
  {
   "first name" : "John",
   "family name" : "Jones"
  }
  </code></pre>
  
  <p>I currently have:</p>
  
  <pre><code>var TableData = new Array();
  var colheaders = new Array();
  var namerows = new Array();
  
  $('.colheaders option:selected').each(function() {
      colheaders.push($(this).val());
  });
  
  var i;
  for (i = 0; i &lt; colheaders.length; i++) { 
      namerows.push('"' + colheaders[i]  + '" : $(tr).find("td:eq(' + i + ')").text()');
  }   
  
  $('#mytable tr').each(function(row, tr) {
      TableData[row] = namerows 
  });
  </code></pre>
  
  <p>However this produces the script and not the cell.</p>
  
  <pre><code>"[[\"\\\"first name\\\" : $(tr).find(\\\"td:eq(0)\\\").text()\\n\",\"\\\family name"\\\" : $(tr).find(\\\"td:eq(1)\\\").text()\\n\",\"\\\"\\\" : $(tr).find(\\\"td:eq(2)\\\").text()\\n\"], 
  </code></pre>
  
  <p>etc..</p>