Possible Duplicate:
Variable name as a string in Javascript
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 :)
I set my variable:
var first_name = "' || i.instructor_fname || '";
I have my input field:
<input type="text" id="first_name" value="' || i.instructor_fname ||'">
and the Escape function:
if (e.keyCode == 27) {
if (document.activeElement.id != "" ) {
$("#" + document.activeElement.id)
.val(document.activeElement.id);
}
}
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.