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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:02:17+00:00 2026-05-25T01:02:17+00:00

A trigger can be applied at the form level and/or at the item level.

  • 0

A trigger can be applied at the form level and/or at the item level. What is the best way for it not to be executed the second time?

<form id='f'>
  <input id='i' type='text' />
</form>

<script>
validate = function(e) { ... }
reformat = function(e) { ... }
document.getElementById('f').addListener('change',validate,true);
document.getElementById('i').addListener('change',validate,true);
document.getElementById('i').addListener('change',reformat,true);
</script>

Context: a data dictionary says item i needs to be validated immediately, and the app writer says all items in the form should be validated immediately.

It’s the same function, usually called once, but sometimes twice.

What’s the best way to keep the validate function from being executing twice?

Note: e.stopPropagation() stops all further calls on the click event, so that the reformat trigger is no longer called.

  • 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-25T01:02:18+00:00Added an answer on May 25, 2026 at 1:02 am

    You can add a prop in the event param to make sure it runs once:

    validate = function(e) { if (e.done) return; /* code */ e.done = true; }
    document.getElementById('f').addListener('change',validate,true);
    document.getElementById('i').addListener('change',validate,true);
    

    DEMO

    Although I don’t see why you’re binding the event twice

    EDIT: For cross browserness (read: IE) change it to this:

    validate = function(e) {
        if ((e = e || window.event).done) return;
        /* code */ 
        e.done = true;
    }
    document.getElementById('f').addListener('change',validate,true);
    document.getElementById('i').addListener('change',validate,true);
    

    Edited DEMO

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

Sidebar

Related Questions

Can a trigger for a table can be applied for tracking in same table?
In a Windows Form window, multiple events can trigger an asynchronous method. This method
Anyone who know how I can trigger the standard HTML5 validation in a form
May I know know I can trigger system to repaint nth row in JList?
I would like to create a small Windows Messenger Client that I can trigger
How can I trigger a stored procedure in SQL Server 2005 based on emails
I can't get didAccelerate to trigger. I have the delegate implemented in my header
How can I set a delayed trigger in JavaScript to execute a function after
I have this Trigger in Postgresql that I can't just get to work (does
Like how the click() can be used to trigger a click event on an

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.