Can't get JavaScript to read an ID as a variable name
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4602141/variable-name-as-a-string-in-javascript">Variable name as a string in Javascript</a>  </p>
</blockquote>



<p>What I'm trying to do is have an input field to edit some information. I'm setting it up so that as each field is changed (a combination of text boxes and checkboxes), AJAX updates the information and shows the changes in a profile box (server load is low, not concerned about efficiency here). If the user hits Escape, I want the value in the text box to revert to the original value (if they were editing a field that they changed their mind on). For the text boxes I've run into a variable issue - I know I can use arrays or hidden fields, but now I want to know how to make this version work :)</p>

<p>I set my variable:</p>

<pre><code> var first_name = "' || i.instructor_fname || '";
</code></pre>

<p>I have my input field:</p>

<pre><code>&lt;input type="text" id="first_name" value="' || i.instructor_fname ||'"&gt;
</code></pre>

<p>and the Escape function:</p>

<pre><code>if (e.keyCode == 27) { 
   if (document.activeElement.id != "" ) {
       $("#" + document.activeElement.id)
                 .val(document.activeElement.id);
   }
}
</code></pre>

<p>For first_name, the output is  first_name.  The value is set correctly, as the text boxes are populated correctly. It seems that I'm not getting 'first_name' to be read as a variable, but as a string. I've tried a few combinations of joining literals to it, but still no luck. Any ideas out there? Again, I know I can use other techniques for this, but it seems like figuring this out might come in handy for other projects.</p>
