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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:31:27+00:00 2026-06-12T02:31:27+00:00

I have a listener on a select element’s change event: on change, a file

  • 0

I have a listener on a select element’s change event: on change, a file is fetched and a complicated SVG is calculated and loaded to the DOM (read: a fair number of CPU cycles required). Issue is if you change the select very quickly (via coded keyboard shortcuts), multiple things are loaded to the SVG container — I only want one loaded at a time. To try to remedy this, I’ve done this (semi-pseudo):

select.on("change", function() { queue(this.val); });

var queuedFile, state = "ready";
function queue(file) {
    queuedFile = file;
    // NB: in real code, queuedFile is a property and the getter empties the queue
    if (state === "ready") { loadFile(queuedFile); }
}

function loadFile(file) {
    state = "busy";

    ajaxGet(file, function(result) {

        // lots of statements, iterators, calls to other fns

        state = "ready";
        // NB: again in real code the getter empties the queue
        var qf = queuedFile;
        if (qf) { clearSVG(); loadFile(qf); }

    }); // end ajaxGet
}

That is to say: on select change, queue the new file and if the file loader is not busy loading another file, load it, else do nothing. When the file loader is done, if there’s a queued file, clear the SVG and load the queued file. Seems like this should only allow one file in the SVG container at once.

In practice, state is never "busy" when it’s checked in queue(), so I’m still getting multiple files loaded to the SVG. A console.log(state) right after state = "busy" shows "busy" though. What am I missing here? I don’t think it’s an issue with the scope of queuedFile.


For completeness, my queue property is this:

// given: all of this code is enclosed in a function that returns an object "viewer".
// (only one instance of the "viewer" is created)

Object.defineProperty(viewer, "queuedFile", {
    get: function () {
        console.log("dequeuing", this.filequeue);
        var buffer = this.filequeue;
        this.filequeue = null;
        return buffer;
    },
    set: function (newval) {
        console.log("queuing", newval);
        this.filequeue = newval;
    }
});
  • 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-12T02:31:28+00:00Added an answer on June 12, 2026 at 2:31 am

    Per the comments, this seems to help you!

    http://jsfiddle.net/2FNsh/1/

    And your fork that ultimately helped:

    http://jsfiddle.net/FkMHw/1/

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

Sidebar

Related Questions

I have this event listener: input_1.addEventListener('input',function(){ updateFromInput(1); },false); It controls the location of a
Is it possible to have keyboard event listener canvas.addEventListener('onkeydown', ev_keydown, false); like we have
Ive used when a select list's option is changed as an event listener, with
The Prototype event listener I use for changes in select menus is not being
I have many select elements in a cart, when a select element changes option
Is it necessary to select the same DOM element and do something to it
I have a listener like this: $('.delete').click(function() { ...some stuff }); Also, on the
I have a listener for click events from which I need to exclude some
If I have a listener for changed tab like this: mTabHost.setOnTabChangedListener(new OnTabChangeListener() { public
I have a message listener (using ActiveMQ) that implements SessionAwareMessageListener. When the onMessage(Message,Session) method

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.