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

The Archive Base Latest Questions

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

I have a jQuery question: I have an ADD button that adds text to

  • 0

I have a jQuery question:

I have an “ADD” button that adds text to the database via AJAX call ($.post()…). The problem is, items are getting repeatedly added. For example:

After page loads: User clicks “ADD” button:

  • the first time, it adds an item.
  • a seconds time, it adds an item and then adds it again (total 2 items)
  • a thrid time, it adds an item and then adds it again and than again (total 3 items)
  • etc…

This is a problem as the data is duplicating.

I’ve narrowed down the problem:

 $(document).ready(function()
 {
  // set event handler for Add button
  bindAddButtonEventListener();
 });

 // set event handler for Add button
 function bindAddButtonEventListener()
 {
  // event handler for the add button
  $("#addRecord").click(function()
  {
   openPopUpBox();

   enablePopUpBoxControls();

   // event handler for Submit button on admin Popup box. Submits data to database
   $("#editPopUp #submitChanges").click(function(event)
   {
    addNewRecord();
   });
  });
 }

 // this method will submit a new record to the server, using AJAX post
 function addNewRecord()
 {
  var obj = buildJSONobject();

  $.post("admin/addRecordToDatabase", obj, function(data)
  {
   displayServerValidation(data);

   cancelPopUpChanges();
   getCatagoriesItems();
  });

  disablePopUpBoxControls();
 }

 // this unbinds the events for the popup box controls
 function disablePopUpBoxControls()
 {
  // unbind event handler for button
  $("#editPopUp #submitChanges").unbind("click", bindEditButtonEventListener);
  //$("#editPopUp #submitChanges").unbind("click", bindAddButtonEventListener);

  // unbind event handler for button
  $("#editPopUp #cancelEdit").unbind("click", enablePopUpBoxControls);
 }

For some reason, inside bindAddButtonEventListener(), when this code runs:

   $("#editPopUp #submitChanges").click(function(event)
   {
    addNewRecord();
   });

addNewRecord() is called again the second time and a third time, the third time and then again. I can’t figure out how to stop it from doing it. I thought that unbinding would help, but it doesn’t seem to. Any help would be much appreciated.

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

    Your main problem is here:

    // unbind event handler for button
    $("#editPopUp #submitChanges").unbind("click", bindEditButtonEventListener);
    

    This doesn’t actually unbind anything, because it wasn’t ever bound to that function, for example:

    $("#editPopUp #submitChanges").click(function(event)
    {
     addNewRecord();
    });
    

    This binds an anonymous function (key point being you can’t reference it like you want later), instead since you’re not using event, bind it directly, like this:

    $("#editPopUp #submitChanges").click(addNewRecord);
    

    Then when you call .unbind() you need to again reference that function:

    $("#editPopUp #submitChanges").unbind("click", addNewRecord);
    

    That’s the fix, as for the “why?”…well since it wasn’t being unbound, it was just racking up a new event handler each time. Every time you clicked #addRecord, it was adding another save handler on the #editPopUp and #submitChanges element click events, properly unbinding as I have above should prevent this.

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

Sidebar

Related Questions

I have a question about some functionality I'm trying to add to my jQuery
i have one question about jquery ajax().. I created a table grid and there
I have this question: How could I call a codebehind method from jquery? I
On my web page I have a button that opens a modal jQuery dialog.
Another jQuery question for you guys. Say I have a url of an image
Really quick jQuery question... I have this function: $(document).ready(function() { $('a#show1').click(function() { $('.item1').toggle(1000); return
I have a question about jQuery load best practice. Imagine the following situation: $(#div).on('click',
i have a very conceptual question regarding jquery. i have this fiddle http://jsfiddle.net/zvCrN/ What
I have a simple question regarding jQuery selectors. I'm using the tablesorter and I
Okay guys, I have read through all the other posts and question on jQuery

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.