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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:24:56+00:00 2026-05-31T13:24:56+00:00

I am using a File Upload script called Simple Photo Manager. When I upload

  • 0

I am using a File Upload script called Simple Photo Manager. When I upload a few images and I want to delete some of them, I have to create a variable numDeleted (number of images deleted)

I will describe the outcome and then I will show you the code.
Please le me know if you know why this is happening

The outcome is:

-Scenario: Three uploaded images are displayed

-I click 1st Delete, div is successfully hidden, then: alert('1')
-I click 2nd Delete, div is successfully hidden, then: alert('2'), alert('3')
-I click 3rd Delete, div is successfully hidden, then: alert('4'), alert('5'),alert('6')

This is the function that is exec when an image is uploaded:

function setUploadedImage(imgSrc, fileTempName, divId) {
    var par = window.document;

    var images = par.getElementById('images_container');
    numDeleted = 0;

    var imgdiv = par.getElementById(divId);
    // all its attributes here...

    var image_new = par.createElement('img');
    // all its attributes here...

    var image_label = par.createElement('input');
    // all its attributes here...

    var image_hidden = par.createElement('input');
    // all its attributes here...

    var image_name = par.createElement('input');
    // all its attributes here...

    var image_del_link = par.createElement('input');
    // all its attributes here...

    var br = par.createElement('br');

    imgdiv.appendChild(image_new);
    imgdiv.appendChild(image_hidden);

    imgdiv.appendChild(image_name);
    imgdiv.appendChild(br);
    imgdiv.appendChild(image_del_link);

    $(".deleteit").click(function(){
             $(this).parent().hide();
             numDeleted = numDeleted + 1;
         alert(numDeleted);
        })
  • 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-31T13:24:57+00:00Added an answer on May 31, 2026 at 1:24 pm

    Need to make some assumptions because of some missing information, but I assume the image_del_link element has the 'deleteit' class.

    If so, you’re binding new handlers to all elements in the DOM with that class. So every time a new one is set up, redundant handlers are added to the ones that already exist.

    Change this…

    $(".deleteit").click(function(){
    

    to this…

    $(image_del_link).click(function(){
    

    …in order to bind only to the newly created element.


    Or a better solution is to use event delegation with the .on() method…

    $('#images_container').on('click', '.deleteit', function(){...
    

    This should be placed outside your setUploadedImage() function so that it’s only run once.

    Any elements with the .deleteit class inside the images_container that are clicked, will trigger the handler placed on images_container.


    If you’re using an older version of jQuery, use .delegate, instead of .on()…

    $('#images_container').delegate('.deleteit', 'click', function(){...
    

    If you’re using a really old version, then upgrade.

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

Sidebar

Related Questions

I am using php script to upload file on some ftp server. When I
I have a standard file upload script using this script. When the upload is
I have created a script to Upload a file using PHP. I have also
i have 3 problems (!) using a mighty simple file-upload-form. i will try to
I have developed a download/upload manager script. When I upload a file via POST
I'm using pycurl to upload a file via put and python cgi script to
I am trying to upload files via FTP using the following script. The file
I'm trying to do a simple file upload using objective c and NSUrlRequest. My
I'm using the following jQuery ( https://github.com/blueimp/jQuery-File-Upload ) script to upload files. This script
hii i am using ajax file upload in this code <script type=text/javascript src=fileuploader.js></script> <script

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.