Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8298357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:44:32+00:00 2026-06-08T15:44:32+00:00

Possible Duplicate: Variable name as a string in Javascript What I’m trying to do

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:44:33+00:00Added an answer on June 8, 2026 at 3:44 pm

    I’m not sure I understand, but perhaps you need to call eval() on document.activeElement.id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: javascript object, access variable property name? I'm trying to call a method
Possible Duplicate: How to get a variable name as a string in PHP? Example:
Possible Duplicate: Get variable name. javascript “reflection” Is there a way to know the
Possible Duplicate: JavaScript Variable inside string without concatenation - like PHP In PHP, double
Possible Duplicate: How to execute a JavaScript function when I have its name as
Possible Duplicate: Pass a PHP string to a Javascript variable (and escape newlines) I
Possible Duplicate: Create new class from a Variable in Java I have a string
Possible Duplicate: Case insensitive string replacement in JavaScript? I am trying to highlight part
Possible Duplicate: javascript object, access variable property name? I'm sure it can be done
Possible Duplicate: Finding the Variable Name passed to a Function in C# In C#,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.