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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:15:01+00:00 2026-05-25T20:15:01+00:00

Assuming that FORM contains INPUT, have the following listeners: JavaScript function formFirst(e) { …

  • 0

Assuming that FORM contains INPUT, have the following listeners:

JavaScript

function formFirst(e) { ... }
function formLast(e) { ... }
function inputFirst(e) { ... }
function inputLast(e) { ... }
function middle(e) { ... }

document.getElementById('form').addEventListener('change',formFirst,true);
document.getElementById('form').addEventListener('change',formLast,false);
document.getElementById('input').addEventListener('change',inputFirst,true);
document.getElementById('input').addEventListener('change',inputLast,false);

Desired order of firing

formFirst()   // normal - outer element, useCapture = true
inputFirst()  // normal - triggering element, declared first
middle()      // -- how to do this?
inputLast()   // normal - triggering element, declared second
formLast()    // normal - outer element, useCapture = false

Nature of problem and attempted solutions

Own code at FORM level, formFirst, formLast and middle, but have no access to INPUT code, inputFirst and inputLast – although could add own listeners on the INPUT.

Attempt 1 modify formFirst() to create and dispatch a new change Event (would be ignored within formFirst) that would call inputFirst(), but have no way of stopping propagation to prevent inputLast() being called subsequently.

Attempt 2 add middle added as listener to INPUT, but cannot guarantee firing order of two listeners of same type and same useCapture.


Premise of Attempt 2 is incorrect – firing order is determined by declaration order within the target Element.

Here are the rules

  1. non-target Element triggers with useCapture=false, starting at the outermost Element and working toward the target Element

    a) if more than one useCapture=true triggers for same element, then order of declaration.

  2. at target Element, order of declaration, regardless of useCapture

  3. non-target Element triggers with useCapture=false, starting at the innermost Element and working away from the target Element

    a) if more than one useCapture=false triggers for same Element, then order of declaration.

  • 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-25T20:15:02+00:00Added an answer on May 25, 2026 at 8:15 pm

    I think that this answers just your question. feel free to comment\contact me for more info.

    —– edit ——

    OK, I just played with it a little as promised, and I found a very simple solution:

    <script type="text/javascript">
    function formFirst(e) { alert(1); }
    function formLast(e) { alert(5); }
    function inputFirst(e) { alert(2); }
    function inputLast(e) { alert(4); }
    function middle(e) { alert(3); }
    
    function init(){
        document.getElementById('form').addEventListener('change',formFirst,true);
        document.getElementById('form').addEventListener('change',formLast,false);
        document.getElementById('input').addEventListener('change',inputFirst,true);
        document.getElementById('input').addEventListener('change',middle,true);
          /*** alternative to last tow lines  
        document.getElementById('input').addEventListener('change',function(){inputFirst();middle();},true);
             **/
        document.getElementById('input').addEventListener('change',inputLast,false);
    }
    
    </script>
    <body onload="init();">
    <form id="form">
    <input type="text" id="input" /> <br />
    </form>
    </body>
    

    notice:

    • I put the addEventListener part into an init function, so I can call it after the page is loaded and the element are already exist.
    • I have run this just on chrome. So I don’t want to guarantee you things about other browsers.
    • An alternative is writing the event handling on your own. here is an example for that. relaying on this article.

      <script type="text/javascript">
      
      function formFirst(e) { alert(1); }
      function formLast(e) { alert(5); }
      function inputFirst(e) { alert(2); }
      function inputLast(e) { alert(4); }
      function middle(e) { alert(3); }
      
      function init(){
      
        //create event
        myHandler = new Event();
      
        //add handler
        myHandler.addHandler(formFirst);
        myHandler.addHandler(inputFirst);
        myHandler.addHandler(middle);
        myHandler.addHandler(inputLast);
        myHandler.addHandler(formLast);
      
        //regiser one listener on some object
        document.getElementById('input').addEventListener('change',function(){myHandler.execute();},true);
      }
      
      
      function Event(){
        this.eventHandlers = new Array();
      }
      
      Event.prototype.addHandler = function(eventHandler){
        this.eventHandlers.push(eventHandler);
      }
      
      Event.prototype.execute = function(){
        for(var i = 0; i < this.eventHandlers.length; i++){
          this.eventHandlers[i]();
        }
      }
      
      
      </script>
      <body onload="init();">
      <form id="form">
      <input type="text" id="input" /> <br />
      </form>
      </body>
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that contains meta-urls in the following form: http://www.xyz.com/.*services/ http://www.xyz.com/.*/wireless
I had assumed that the canonical form for operator+, assuming the existence of an
Assuming that I have a CronTriggerBean similar to <bean id=midMonthCronTrigger class=org.springframework.scheduling.quartz.CronTriggerBean> <property name=jobDetail ref=reminderJobDetail
Assuming that best practices have been followed when designing a new database, how does
Assuming that I have a typedef declared in my .h file as such: typedef
I'm trying to make a simple form that contains textboxes that draw from a
Assuming that you already have created an oauth client app in twitter, you can
Assuming Visual C/C++ 6, I have a complex data structure of 22399 elements that
I have a pretty simple form that I am wanting to localize (I actually
I have a form with 10 input textboxes and each of them have a

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.