value of hidden input is always 0
<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='" + GetFormImageCount + "' /&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='" + GetFormImageCount + "' /&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>The problem is that there is no value in either form. The value of both forms are still 0. What do I need to include in code below to be able to include the correct value for the correct form?</p>

<p>Below is the code:</p>

<pre><code>...//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);                             



});

//BELOW IS THE FUNCTION WHICH SHOULD INSERT THE VALUE FOR THE HIDDEN INPUT FOR EACH FORM

function GetFormImageCount(){ 
  var frm = $('.imageuploadform'); 

    if(frm[0] != undefined) 
    { 
       if(length in frm ) 
       { 
          return  frm.length; 
       } 
        return 1; 
    } 
    return 0; 
}
</code></pre>
