title: Getting value of multiple input boxes into multidimensional array using jquery
body: <p>I have multiple input elements arranged in 16 rows and 5 columns (Just like a grid) . The contents of the 16 rows are inserted into a mysql table as 16 records with each record contains 5 fields. I want a method to get the value of all the input into an array using jquery and pass this to a ajax post request.</p>
  
  <p>dataentry.php contains this code</p>
  
  <pre><code>jQuery('#metentry').submit(function(e){
       e.preventDefault(); 
  
   // getting data from form to variables
   var date=jQuery('#stddate').val();
   var kgsunit=jQuery('#unit').val();
   var kgsshift=jQuery('#shift').val();
  
  
  //sending data to script
   jQuery.post("get_blank_form.php", {
   "date":date, 
   'unit':kgsunit,
   'shift':kgsshift, 
   },    function(data) {      
  
    //displaying message
  jQuery('#blankform').html(data);
  jQuery('#formpanel').hide();
  
  
    });
  </code></pre>
  
  <p>get_blank_form.php contains this code:</p>
  
  <pre><code>echo'&lt;form id="shiftentry" name="shiftentry" &gt;';
  
  
   echo "Date:&lt;input id=shiftdate value='".$date."'/&gt;"; 
   echo "Unit:&lt;input id=shiftdate value='".$unit."'/&gt;";
   echo "Shift:&lt;input id=shiftdate value='".$shift."'/&gt;&lt;br/&gt;";
  
     echo "&lt;table&gt;&lt;tr&gt;&lt;th&gt;No&lt;/th&gt;&lt;th&gt;Ele&lt;/th&gt;&lt;th&gt;Location&lt;/th&gt;&lt;th&gt;Drate &lt;/th&gt;&lt;th&gt;H3 Val &lt;/th&gt;&lt;th&gt;Part &lt;/th&gt;   &lt;th&gt;Iod&lt;/th&gt;&lt;th&gt;Cont. &lt;/th&gt;&lt;/tr&gt;";
              while($row2=mysql_fetch_array($result_sec))
                  { 
                  echo "&lt;tr&gt;";
                  echo "&lt;td&gt;".++$rc."&lt;/td&gt;";
                  echo "&lt;td&gt;&lt;input size='5' id='".$row2['ele']."' value='".$row2['ele']."' /&gt;&lt;/td&gt;";
                  echo "&lt;td&gt;&lt;input id='".$row2['loc_id']."' value='".$row2['loc']."' /&gt;&lt;/td&gt;";
                  echo "&lt;td&gt;&lt;input size='5' id='drate".$rc."'  value='".$row2['drate']."'/&gt;&lt;/td&gt;";
                  echo "&lt;td&gt;&lt;input size='5' id='h3".$rc."' value='0' /&gt;&lt;/td&gt;";
                  echo "&lt;td&gt;&lt;input size='5' id='part".$rc."' value='0' /&gt;&lt;/td&gt;";
                  echo "&lt;td&gt;&lt;input size='5' id='iod".$rc."' value='0' /&gt;&lt;/td&gt;";
                  echo "&lt;td&gt;&lt;input size='5' id='cont".$rc."' value='0' /&gt;&lt;/td&gt;";
                  echo "&lt;/tr&gt;";
              }
  
  
  
    echo " &lt;/table&gt;";
  
  
  
     echo '&lt;div align="center"&gt;';
     echo '&lt;input type="submit" id="submit2" name="submit2" value="Submit" width="30" /&gt;';
     echo '&lt;/div&gt;';
  
   echo '&lt;/form&gt;';
  </code></pre>
  
  <p>Both the above scripts are working and  this will add a form"shiftentry" to the DOM in dataentry.php. This form conains around 21 rows and 8 columns containing input elements. I want a method to get the values in this 21 x 8 input elements and pass it to a jQuery post request. There are two issues.</p>
  
  <ol>
  <li>Since the form is added after the DOM is loaded, how to get the value? </li>
  <li>Is there any way to read all the input values using a loop instead of separate lines for each input element?</li>
  </ol>
  
  <p>My final aim is to append this 21 rows into a mysql table. This part I knew, once I get all the values. Any suggestions ?</p>
  
  <p>I have this function which create a multi dimensional array of input values. But in this casethe 'form1' is loaded before DOM is completed. But in the above scenario, form is dynamically added after DOM loding is completed</p>
  
  <pre><code>jQuery('#form1').submit(function(e){
       e.preventDefault(); 
  
          var arr = jQuery('#form1 tr:gt(0)').map(function() {
      return [jQuery('input', this).map(function() {
          return this.value;
      }).get()];
  }).get();
  
  
  });
  </code></pre>
  
  <p>I also have another jquery script in this page which is used to traverse through the input boxes (obviously, these input boxes are loaded after DOM)</p>
  
  <pre><code>jQuery(document).delegate('input','keyup',function(e){
  if(e.which==39)
  jQuery(this).closest('td').next().find('input').focus();
  else if(e.which==37)
  jQuery(this).closest('td').prev().find('input').focus();
  else if(e.which==40)
  jQuery(this).closest('tr').next().find('td:eq('+jQuery(this).closest('td').index()+')').find('input').focus();
  else if(e.which==38)
  jQuery(this).closest('tr').prev().find('td:eq('+jQuery(this).closest('td').index()+')').find('input').focus();
  });
  </code></pre>
  
  <p>How can I use the delegate option in the script used for traverse in the script for getting input values?</p>