title: Is it possible to get the value of a <td> element using onclick?
body: <p>I currently have a table that has a list of email template names being echoed using php.  Below is part of the php code.  I'm trying to grab the table value and pass it to my JS file where a future AJAX command will pass it to a different file (that I won't have any issues with).  My first attempt to alert out the value stated that the value was undefined.  My second attempt showed the type of element it was inside (at the time it was a span).  Now it's not showing anything.  Suggestions?</p>
  
  <p>PHP code:</p>
  
  <pre><code>&lt;table class="departments"&gt;
  &lt;tr&gt;
  &lt;th scope="col" style="width: 175px;"&gt;Email Name&lt;/th&gt;
  ';
  $get_depts = mysql_query("SELECT dept_name FROM depts where bus_id = '{$_SESSION['bus_id']}'");
  while(($department = mysql_fetch_assoc($get_depts)))
  {
      echo '
      &lt;th scope="col" style="width: 175px;"&gt;'.$department['dept_name'].'&lt;/th&gt;
      ';
  }
  echo '
  &lt;/tr&gt;
  ';
  $get_emails = mysql_query("SELECT id, email_name from emails where bus_id = '{$_SESSION['bus_id']}' ORDER BY email_name ASC");
  while(($email = mysql_fetch_assoc($get_emails)))
  {
      echo '
      &lt;tr&gt;
      &lt;td id="test" onclick="moveValue()"&gt;'.$email['email_name'].'&lt;/td&gt;
      ';
  </code></pre>
  
  <p>Current JS code:</p>
  
  <pre><code>function moveValue()
  {
  var x = document.getElementById(test);
  var y = x.innerHTML;
  alert(y);
  } 
  </code></pre>