title: Date Picker doesn't show on PHP input created inside for loop
body: <p>I am creating inputs dynamically inside a php foreach loop. I am assigning a class date-pick to the textboxes where I am suppose to add the datepicker. After the loop, the date-picker appears only on the first instance and the rest do not have. Aside from this, it causes my other jquery to fail, showing an error on console: <code>Uncaught TypeError: Cannot read property '1' of null date.js:477</code></p>
  
  <p>Here is my php code for the loop:</p>
  
  <pre><code>&lt;?php
  for ($i=0; $i&lt;$poterms; $i++)
  {
     $lastcb=$lastcb+ 1;
     $nextdate=date('d-m-Y', strtotime($nextdate. ' + 30 days'));
   ?&gt;
     &lt;tr class="row1"&gt;
     &lt;td&gt;&lt;input  class="date-pick" value="&lt;?php echo $nextdate; ?&gt;" /&gt;&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" class="chkno" name="CheckNo" id="CheckNo&lt;?php echo $i;?&gt;" value="&lt;?php echo $lastcb;?&gt;"/&gt;&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" class="chkval" name="Amount" value="&lt;?php echo $checkamt;?&gt;" onKeyup ="updatechecktotal()" /&gt;&lt;/td&gt;
     &lt;/tr&gt;
   &lt;?php
     $nextdate=date('d-m-Y', strtotime($nextdate. ' + 30 days'));
  }
  ?&gt;
  </code></pre>
  
  <p>Here is where i call the datepicker function:</p>
  
  <pre><code>$(function()
  {
  $('.date-pick').datePicker().val(new Date().asString()).trigger('change');
  });
  </code></pre>
  
  <p>Here is the part where the error is pointed at date.js</p>
  
  <pre><code>Date.fromString = function(s)
  {
  var f = Date.format;
  var d = new Date('01/01/1970');
  if (s == '') return d;
      s = s.toLowerCase();
  var matcher = '';
  var order = [];
  var r = /(dd?d?|mm?m?|yy?yy?)+([^(m|d|y)])?/g;
  var results;
  while ((results = r.exec(f)) != null)
  {
      switch (results[1]) {
      case 'd':
      case 'dd':
      case 'm':
      case 'mm':
      case 'yy':
      case 'yyyy':
      matcher += '(\\d+\\d?\\d?\\d?)+';
      order.push(results[1].substr(0, 1));
      break;
      case 'mmm':
      matcher += '([a-z]{3})';
      order.push('M');
      break;
    }
  if (results[2]) {
  matcher += results[2];
  }
  
  }
  var dm = new RegExp(matcher);
  var result = s.match(dm);
  for (var i=0; i&lt;order.length; i++) {
      var res = result[i+1]; //line 477
      switch(order[i]) {
      case 'd':
      d.setDate(res);
      break;
      case 'm':
      d.setMonth(Number(res)-1);
      break;
      case 'M':
      for (var j=0; j&lt;Date.abbrMonthNames.length; j++) {
          if (Date.abbrMonthNames[j].toLowerCase() == res) break;
      }
      d.setMonth(j);
      break;
      case 'y':
      d.setYear(res);
      break;
      }
      }
  
      return d;
  };
  </code></pre>
  
  <p>This drives me crazy...</p>