It is only uploading first row's file input
<p>I have a application which you can access <a href="https://helios.hud.ac.uk/u0867587/Mobile_app/QandATable2.php" rel="nofollow">here</a>. If you open the application please click on the "Add" button a couple of times. This will add a new row into a table below. In each table row there is an AJAX file uploader.</p>

<p>Now the problem is that if I click on the "Upload" button in any row except the first row, then the uploading only happens in the first row so it is only uploading the first file input only.</p>

<p>Why is it doing this and how can I get it so that when then the user clicks the "Upload" button, the file input within that row of the "Upload" button is uploaded and not the first row being uploaded? </p>

<p>Below is the full code where it appends the file AJAX file uploaded in each table row:</p>

<pre><code>function insertQuestion(form) {   

    var $tbody = $('#qandatbl &gt; tbody'); 
    var $tr = $("&lt;tr class='optionAndAnswer' align='center'&gt;&lt;/tr&gt;");
    var $image = $("&lt;td class='image'&gt;&lt;/td&gt;"); 


    var $fileImage = $("&lt;form action='upload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='startUpload();' &gt;" + 
    "&lt;p id='f1_upload_process' align='center'&gt;Loading...&lt;br/&gt;&lt;img src='Images/loader.gif' /&gt;&lt;br/&gt;&lt;/p&gt;&lt;p id='f1_upload_form' align='center'&gt;&lt;br/&gt;&lt;label&gt;" + 
    "File: &lt;input name='fileImage' type='file' class='fileImage' /&gt;&lt;/label&gt;&lt;br/&gt;&lt;label&gt;&lt;input type='submit' name='submitBtn' class='sbtn' value='Upload' /&gt;&lt;/label&gt;" +
    "&lt;/p&gt; &lt;iframe id='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px solid #fff;'&gt;&lt;/iframe&gt;&lt;/form&gt;");

    $image.append($fileImage);

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

}

function startUpload(){
      document.getElementById('f1_upload_process').style.visibility = 'visible';
      document.getElementById('f1_upload_form').style.visibility = 'hidden';
      return true;
}

function stopUpload(success){
      var result = '';
      if (success == 1){
         result = '&lt;span class="msg"&gt;The file was uploaded successfully!&lt;\/span&gt;&lt;br/&gt;&lt;br/&gt;';
      }
      else {
         result = '&lt;span class="emsg"&gt;There was an error during file upload!&lt;\/span&gt;&lt;br/&gt;&lt;br/&gt;';
      }
      document.getElementById('f1_upload_process').style.visibility = 'hidden';
      document.getElementById('f1_upload_form').innerHTML = result + '&lt;label&gt;File: &lt;input name="fileImage" type="file"/&gt;&lt;\/label&gt;&lt;label&gt;&lt;input type="submit" name="submitBtn" class="sbtn" value="Upload" /&gt;&lt;\/label&gt;';
      document.getElementById('f1_upload_form').style.visibility = 'visible';      
      return true;   
}
</code></pre>

<p>UPDATE:</p>

<p>Current Code:</p>

<pre><code> var $fileImage = $("&lt;form action='upload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='startUpload(this);' &gt;" + 
    "&lt;p class='f1_upload_process' align='center'&gt;Loading...&lt;br/&gt;&lt;img src='Images/loader.gif' /&gt;&lt;br/&gt;&lt;/p&gt;&lt;p class='f1_upload_form' align='center'&gt;&lt;br/&gt;&lt;label&gt;" + 
    "File: &lt;input name='fileImage' type='file' class='fileImage' /&gt;&lt;/label&gt;&lt;br/&gt;&lt;label&gt;&lt;input type='submit' name='submitBtn' class='sbtn' value='Upload' /&gt;&lt;/label&gt;" +
    "&lt;/p&gt; &lt;iframe class='upload_target' name='upload_target' src='#' style='wclassth:0;height:0;border:0px solclass #fff;'&gt;&lt;/iframe&gt;&lt;/form&gt;");

function stopUpload(success, source_form){
      var result = '';
      if (success == 1){
         result = '&lt;span class="msg"&gt;The file was uploaded successfully!&lt;\/span&gt;&lt;br/&gt;&lt;br/&gt;';
      }
      else {
         result = '&lt;span class="emsg"&gt;There was an error during file upload!&lt;\/span&gt;&lt;br/&gt;&lt;br/&gt;';
      }
      $(source_form).find('.f1_upload_process').style.visibility = 'hidden';
      $(source_form).find('.f1_upload_form').innerHTML = result + '&lt;label&gt;File: &lt;input name="fileImage" type="file"/&gt;&lt;\/label&gt;&lt;label&gt;&lt;input type="submit" name="submitBtn" class="sbtn" value="Upload" /&gt;&lt;\/label&gt;';
      $(source_form).find('.f1_upload_form').style.visibility = 'visible';      
      return true;   
}
</code></pre>

<p>Why am I getting an error on this line below:</p>

<pre><code>$(source_form).find('.f1_upload_form').style.visibility = 'visible'; 
</code></pre>
