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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:30:43+00:00 2026-06-08T19:30:43+00:00

I am new to java script and having a problem. I am creating a

  • 0

I am new to java script and having a problem.

I am creating a form dynamically from Json string what we obtain some how ( not relevant ) – Keeping all those controls information in Array (allParamArray in code) . A control can have parent , hence a parent control can have dependents ( children ) – I want to attach onchange event to each control which have dependents . The dependents are comma separated and taken care of in the refreshDependents function.

<code>

for (mp = 0; mp < allParamsArray.length; mp++) { 
    if (allParamsArray[mp].dependents) {
        var parent = allParamsArray[mp].name;
        var dependents = allParamsArray[mp].dependents;
        document.getElementById(parent).onchange = function() {
           refreshDependents(parent, dependents, this.selectedIndex)
        };
    }
}
</code>

The Problem is , when I change value on form for a control refreshDependents has the last parent information and not of the control which I change.

I was wondering is there any way we can achieve multiple control pointing to same onchange function and in onchange function we get the correct information about the control which is being changed ?

  • 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-08T19:30:44+00:00Added an answer on June 8, 2026 at 7:30 pm

    This should do it:

    function makeHandler(parent, dependents, selectedIndex){
        return function(){
            refreshDependents(parent, dependents, selectedIndex);
        };
    }
    
    for (mp = 0; mp < allParamsArray.length; mp++) {
        if (allParamsArray[mp].dependents) {
            var parent = allParamsArray[mp].name;
            var dependents = allParamsArray[mp].dependents;
            document.getElementById(parent).onchange = makeHandler(parent, dependents, this.selectedIndex);
        }
    }
    

    The makeHandler function returns a new function object, which will keep the values that the parent, dependents, and selectedIndex variables had at the time it was created.

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

Sidebar

Related Questions

I am new to Javascript and am having some difficulty. I want to have
I'm pretty new to JavaScript and I'm having trouble with some of the properties
greetings, I'm new with java script so bear with me! I want to achieve
I am new in share point. I want to select data using java script
I am executing groovy script in java: final GroovyClassLoader classLoader = new GroovyClassLoader(); Class
I'm new with Google map. I'm having problem in rebinding the data in my
I am fairly new to javascript and DOM and I am having a problem
Ok, so I'm REALLY new to programming and javascript, but I'm having a problem
I'm new to JavaScript, and am having a problem understanding this code: function addProperty(o)
I'm having a problem with this JavaScript script. I've tried a number of things

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.