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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:28:08+00:00 2026-05-13T20:28:08+00:00

Say, I have two HTML elements – an input field and a button. The

  • 0

Say, I have two HTML elements – an input field and a button.

The code for both is generated programatically.

After I generate the code, I have a function that binds event handlers to those elements.

//Locate add to order button and bind event handler to it
this.input_add = document.getElementById("add_to_order");
this.input_add.onclick = 
    function () {
        return controller.addToOrder.call(controller);
    };

// Locate quantity input and bind event handler to it
this.input_quantity = document.getElementById("form_quantity");
this.input_quantity.onkeyup = 
    function () {
        return controller.changeQuantity.call(controller, this);
    };

Here’s the puzzle – controller.changeQuantity requires a reference to this.input_add.

As far as I can tell, I can’t pass this.input_add into the call parameter list for controller.changeQuantity.

I’ve found only one solution – putting a reference to this.input_add in the this.input_quantity object.

this.input_quantity.addButton = this.input_add

Are there any alternatives? Is this a good practice? I’m trying to keep my application as decoupled as possible.

  • 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-05-13T20:28:08+00:00Added an answer on May 13, 2026 at 8:28 pm

    Add your DOM objects to your “controller”, and set up your event handlers as part of that object, something like:

    var controller = { ... };
    controller.input_add = document.getElementById("add_to_order");
    controller.input_quantity = document.getElementById("form_quantity");
    
    controller.input_add.onclick = function() { controller.addToOrder.call(controller, this);}
    

    Then you can reference these DOM elements from within your controller object at any point.

    I often set up references to DOM elements, register event handlers, etc. in the setup code for my main Javascript controller object.

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

Sidebar

Ask A Question

Stats

  • Questions 351k
  • Answers 351k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you are using built in web cam most of… May 14, 2026 at 7:13 am
  • Editorial Team
    Editorial Team added an answer 1454.12 1.95 85.3955 122.11 50.0 Keep prices aligned by decimal-separator… May 14, 2026 at 7:13 am
  • Editorial Team
    Editorial Team added an answer Change redirect_to to render in else condition otherwise checkout method… May 14, 2026 at 7:13 am

Related Questions

I'm having a little trouble figuring out a fast way to accomplish a (seemingly)
I have a php page that produces an array of elements. For the sake
Say I have an xml document consisting of a list as shown below: <Items>
I have just asked these two questions, one on flash seo url best practices
When you want to add whitespace between HTML elements (using CSS), to which element

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.