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

  • SEARCH
  • Home
  • 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 8020055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:34:56+00:00 2026-06-04T21:34:56+00:00

I am trying to figure out how to call a javascript function using text

  • 0

I am trying to figure out how to call a javascript function using text taken off an div id using jquery like this:

$('#selector').attr('id');

The id returned is a text object, which I want to use to call an javascript object of the same name. Basically I have an appointment in a calendar and set of objects holding the various variables such as reason, times, locations etc in the background. These objects have been created using a custom constructor function like this.

function appt(id,...){
  this.id;
  etc...
 }
 var appt12 = new appt(id,...);

I then want to be able to call it as an object along the lines of var id = appt12.id.

I have found I can use eval to do this, but there seems to be a lot of debate in this forum on the use of eval. I am concerned it could be slow, on security it will only be called in browser so most of the security will occur in my php.

Using eval would look like this:

var apptObj = eval(apptid);

after passing to eval the text id can be used as a reference to an object. Although my reading of other posts is that this is not best practice.

Any thoughts on a non-eval approach to solving this problem.

Thanks in advance.

  • 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-04T21:34:57+00:00Added an answer on June 4, 2026 at 9:34 pm

    You should hold the functions in an object like this:

    var operations = {
        "add": function(){...},
        "remove": function(){...},
        "edit": function(){...}
    };
    

    Then call it like this:

    var op = element.id;
    operations[op]();
    

    You could use the global window object that Ufuk mentioned, but it is generally frowned upon. If you have several related functions, keeping them in an object and preventing them from floating in the global scope is considered cleaner and more organized.

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

Sidebar

Related Questions

So i am trying to call this function in my javascript but it gives
I'm trying to wrap my head around Javascript's function.apply(). You use it like this:
Trying to figure out why this swf which is loaded via javascript which is
Trying to figure out the best way to do this: Should I do something
Trying to figure out how to write a jquery formula that will sum all
Trying to figure out this pseudo code. The following is assumed.... I can only
I'm trying to figure out how to call C# methods in my BHO object
I'm new to JavaScript. I am trying to figure out how I would create
I've been trying to figure this out, but it seems to be harder than
I'm trying to figure out how to bind a javascript event to a select

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.