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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:11:18+00:00 2026-06-14T21:11:18+00:00

I have this code in my project, that uses Prototype 1.7.1 var Worker =

  • 0

I have this code in my project, that uses Prototype 1.7.1

var Worker = Class.create({
    initialize: function() {
        this.ap = $('ap');

        alert( this.ap.value );

        $( 'main-form' ).on( 'change', '.inputs', this.recount );
        this.ap.observe( 'keypress', this.recount );
    },
    recount: function() {
        alert( this.ap.value );
    }
});
document.observe('dom:loaded', function(){
    var w = new Worker();
});

Item of id="ap" is text input field inside a form. Inside above class initializer, #ap element is found, this.ap member is assigned ( alert shows correct value ).

Now, when I change #ap input value, recount method called by keypress event gives me an error – this.ap is undefined. After I click outside of this input, to loose focus, recount method called by change event works correctly ( this.ap is assigned ).

  • 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-14T21:11:19+00:00Added an answer on June 14, 2026 at 9:11 pm

    Sure, the handler will be executed in context of the DOM element – this does not point to your Worker instance. Use

    $( 'main-form' ).on( 'change', '.inputs', this.recount.bind(this) );
    

    Btw, it is not a good idea to name your class “Worker” – this would overwrite the global WebWorker constructor.

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

Sidebar

Related Questions

I have this code that uses the USE_CONVERSION macro in a C++ project... I
I currently have a project that uses g++ to compile it's code. I'm in
I have an Android project that contains a class that uses JNI to pull
I have got this project that uses excel for some calculation. This excel is
The Scenario I have an ASP.Net Web Project that uses a master page. This
I have a project that uses some legacy script for processing the source code.
I have a C++/CLI project that uses CWinFormsControl and CWinFormsView to create .NET controls
I have a big Maven project that uses the PMD plugin for code quality
I have a project that uses GLSL shaders. This project is designed not to
I have a web project that uses a custom configuration class to store app

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.