Note that there are some explanatory texts on larger screens.

plurals
  1. POWrong value in my hidden input
    primarykey
    data
    text
    <p>I am having trouble getting the correct value in my hidden input.</p> <p>Below I have a form which gets appended into a table everytime he user clicks a button:</p> <pre><code> var $fileImage = $("&lt;form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target_image' onsubmit='return imageClickHandler(this);' class='imageuploadform' &gt;" + "&lt;p class='imagef1_upload_form' align='center'&gt;&lt;br/&gt;&lt;span class='msg'&gt;&lt;/span&gt;&lt;label&gt;" + "Image File: &lt;input name='fileImage' type='file' class='fileImage' /&gt;&lt;/label&gt;&lt;br/&gt;&lt;br/&gt;&lt;label class='imagelbl'&gt;" + "&lt;input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /&gt;&lt;/label&gt;" + "&lt;input type='hidden' class='numimage' name='numimage' value='" + numimage + "' /&gt;&lt;/p&gt;" + "&lt;iframe class='upload_target_image' name='upload_target_image' src='#' style='width:0px;height:0px;border:0px;solid;#fff;'&gt;&lt;/iframe&gt;&lt;/form&gt;"); $image.append($fileImage); </code></pre> <p>Now this is the problem I am recieving and it deals with the hidden input in the form:</p> <pre><code>&lt;input type='hidden' class='numimage' name='numimage' value='" + numimage + "' /&gt; </code></pre> <p>Lets say I append two forms into a table, one form in row 1 (value in hidden input should be 1) and one form in row 2 (value in hidden input should be 2).</p> <p>Now if I upload a file using form 1, then the value in hidden input equals 1 which is correct. If I then upload a file using form 2, then the value in the input equals 2. This is fine.</p> <p>The problem is that if I revert back to form 1 and upload another file, because of the way I have coded it, the value of the hidden input is still 2 when it should really be 1.</p> <p>So what my question is that how can the code below be changed so that the value of the hidden input is the number depending on which form is used to upload the file, (value = 1 for form 1 used, value = 2 for form 2 used, value =3 for form 3 used etc)</p> <p>Below is the code:</p> <pre><code>var numimage = 0; ...//form code from top goes here //CODE BELOW INCREMENTS A QUESTION NUMBER AND INCREMENTS THE HIDDEN VALUE FOR EACH ROW ADDED $('.num_questions').each( function() { var $this = $(this); var $questionNumber = $("&lt;input type='hidden' class='num_questionsRow'&gt;").attr('name',$this.attr('name')+"[]") .attr('value',$this.val()); $qid.append($questionNumber); ++numimage; $(".numimage").val(numimage); }); //BELOW STARTS THE UPLOADING OF THE FILE function startImageUpload(imageuploadform){ $(imageuploadform).find('.imagef1_upload_process').css('visibility','visible'); $(imageuploadform).find('.imagef1_cancel').css('visibility','visible'); $(imageuploadform).find('.imagef1_upload_form').css('visibility','hidden'); sourceImageForm = imageuploadform; }); //BELOW IS CODE FOR WHEN FILE UPLOAD STOPS function stopImageUpload(){ $(sourceImageForm).find('.imagef1_upload_form .msg').html(result); $(sourceImageForm).find(".fileImage").replaceWith("&lt;input type='file' class='fileImage' name='fileImage' /&gt;"); $(sourceImageForm).find('.imagef1_upload_form').css('visibility','visible'); return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload