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 7727199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:24:00+00:00 2026-06-01T05:24:00+00:00

I’m creating a javavascript object which I’m calling rulesObject. The idea is for it

  • 0

I’m creating a javavascript object which I’m calling rulesObject. The idea is for it to be a javascript object containing all of the rules I need to check to enable/disable other checkboxes that is dynamically generated from a mysql database at the very beginning of the script. For now, I’m just testing it out with two rules which I know create the scenario I’m looking for, so here’s what my object looks like at the moment:

rulesObject = {
        chk533570 : ["533577", "503671", "503667", "604028", "503661"],
        chk503928 : ["533577", "533578","503671", "503666", "533576", "503667", "324201", "503221", "604028", "503668", "533580", "503669", "533579", "533581", "503670"]
};    

Now what I need to do is access the information out of that object. If I do a simple alert(rulesObject. chk533570), it works PERFECTLY – gives me exactly what I need. However, what I’m going to need to do is access a specific rule based on what was just clicked by running through the following. So, for example, if I clicked the checkbox valued “533570”, it would go through the following:

$('input').click(function(){            
if(this.checked) { 
    checkRules(this.value, 'checked'); 
} else { 
    checkRules(this.value, 'unchecked'); 
}           
});    

(Of course I’m using jQuery there, but I’m using it throughout the web app so I don’t mind going back and forth.)

Now onto my checkRules function. It’s still very simple as it’s in the beginning stages – I just want to alert the value of what I just selected. Again, if I do alert(rulesObject. chk533570), even within the function, I get the right result, but I need to access what I just selected, so I have to add the letters ‘chk’ to the beginning of the object property name and then append the justselected value (which in this case equals 533570). Here are the ways I’ve tried to do it:

function checkRules(justselected, state) { 
        rulename= 'chk' + justselected;
        currentrules = rulesObject.rulename;

        alert(rulename);        
        alert(currentrules); 
}

Alert 1: chk533570
Alert 2: undefined

function checkRules(justselected, state) { 
        rulename= 'chk' + justselected;

        alert(rulesObject.rulename); 
}     

Alert: Undefined

function checkRules(justselected, state) { 
        rulename= 'chk' + justselected;

        alert(rulesObject + '.chk' + justselected); 
}     

Alert: [object Object].chk533570

function checkRules(justselected, state) {     
        alert(rulesObject.chk533570);
}     

Alert: 533577,503671,503667,604028,503661

So, any idea how to properly call that name so that I get the right results? I also tried not having the ‘chk’ in there at all, but the javascript object didn’t like a completely numeral property.

  • 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-01T05:24:02+00:00Added an answer on June 1, 2026 at 5:24 am

    obj.key is the same as obj['key'] – but in the second way the key can be dynamic since it’s a plain JavaScript expression.

    So you can simply use rulesObject['chk' + justselected]:

    function checkRules(justselected, state) {     
            alert(rulesObject['chk' + justselected]);
    }
    

    Long time ago people used to use alert(eval('rulesObject.chk' + justselected)); by the way. While this works, do not use this. Using eval() should be avoided at all times; and in this case there is a much cleaner way anyway.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.