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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:00:01+00:00 2026-06-02T23:00:01+00:00

I have an application you can access [here][1]. When you open up the application,

  • 0

I have an application you can access [here][1]. When you open up the application, you will see an “Add” button on top, click this twice and you will see 2 table rows appear with each row containing it’s own file input.

The problem is: suppose you try to upload a file (a small file for quick upload) in the second row’s file input. After you have uploaded a file, the name of the file which has been uploaded is appended into both the top row and the second row. This is incorrect, it should only append the file name in the second row only because you used the second row’s file input to upload that file.

How can I append the file name within the same row as the file input used to upload the file?

Below is the code for the form which contains the file input:

 function insertQuestion(form) {  

  var $tbody = $('#qandatbl > tbody'); 
  var $tr = $("<tr class='optionAndAnswer' align='center'></tr>");
  var $image = $("<td class='image'></td>"); 

    var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='return imageClickHandler(this);' class='imageuploadform' >" + 
    "Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/><label class='imagelbl'>" + 
    "<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>" + 
    "<label><input type='button' name='imageClear' class='imageClear' value='Clear File'/></label>" +
    "</p><ul class='listImage' align='left'></ul>" +
    "<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe></form>");

    $image.append($fileImage);

    $tr.append($image);  
    $tbody.append($tr);

    };

Below is the handler the form directs to when clicked:

 function imageClickHandler(imageuploadform){ 
      if(imageValidation(imageuploadform)){ 
          return startImageUpload(imageuploadform); 
      } 
      return false;
  }

Below is where the file uploading starts and stops:

function startImageUpload(imageuploadform){

  $(imageuploadform).find('.imagef1_upload_process').css('visibility','visible');

      return true;
}


    function htmlEncode(value) { return $('<div/>').text(value).html(); }


    function stopImageUpload(success, imagefilename){

          var result = '';

          if (success == 1){
             result = '<span class="msg">The file was uploaded successfully!</span><br/><br/>';      
              $('.listImage').append('<div>' + htmlEncode(imagefilename) + '<button type="button" class="deletefileimage">Delete</button><br/><hr/></div>'); 
          }
          else {
             result = '<span class="emsg">There was an error during file upload!</span><br/><br/>';
          }

  $(".deletefileimage").on("click", function(event) {

    $(this).parent().remove();

});

    return true;

    } 

CORRECT SOLUTION:

     function imageClickHandler(imageuploadform){ 
          if(imageValidation(imageuploadform)){ 
 window.lastUploadImageIndex = $('.imageuploadform').index(imageuploadform); 
              return startImageUpload(imageuploadform); 
          } 
          return false;
      }

         $('.listImage').eq(window.lastUploadImageIndex).append('<div>' + htmlEncode(imagefilename) + '<button type="button" class="deletefileimage">Delete</button><br/><hr/></div>'); 
  • 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-02T23:00:06+00:00Added an answer on June 2, 2026 at 11:00 pm

    Your basic problem is:

    $(‘.listImage’)

    That is a selector for “any element with the class ‘listImage'”. Since you’ve clicked add twice, there are two elements with this class, and your selector matches (and appends) to both of them.

    Use a more specific selector for your append and you should be all set.

    Unfortunately, I can’t recommend a specific way of doing that, because I don’t know how your stopImageUpload function is being called. If it’s being triggered by a jQuery event handler, then you can refer to “this” inside your function to get the element that triggered the event, and you should be able to use that to figure out which .listImage to append to.

    If it’s not triggered by an event handler, then I would imagine that whatever function is calling it knows which file input triggered things.

    Once you know which element you actually want to append to, you can target it using jQuery’s eq method/selector. Here are a couple examples:

    $('.listImage:eq(0)') // selects the first listImage only
    $('.listImage').eq(2) // selects the third listImage only 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application you can access here When you open the app, please
I have a application which you can access here . If you open the
I have a jsfiddle application which you can access here . Now when you
We have a web application where you can access two services/functions (Buy and Rent).
I have a console application which can also open winform under certain conditions.Processing(its a
I have an Access application that's currently using the fhandlefile() procedure here: http://access.mvps.org/access/api/api0018.htm ...to
I have an application that can filter a datagridview based on date using a
I have an application that can be viewed with landscape and portrait mode. I'm
I have an application that can potentially have hundreds of memory mapped, i.e., mmap()
In C++, a console application can have a message handler in its WinMain procedure,

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.