title: adding multiple rows with date on php form
body: <p>ive been stuck with this for almost a week,</p>
  
  <p>ive been trying to add multiple rows to a section of my form without reloading the page,
  i cloned the fields and put them in an array but the problem is the dates, it can't be placed in an array ... can anybody help me out, it would be much appreciated ... thanks.</p>
  
  <p>here is my code:</p>
  
  <p>index.php</p>
  
  <pre><code>&lt;DIV id="mainContent_pnlEmploymentHistory"&gt;
  &lt;form id="form1" name="form1" method="post" action="value.php"&gt;
  &lt;TABLE id="dataTable"&gt;
    &lt;TBODY&gt;
    &lt;TR&gt;
      &lt;TD style="width: 310px; height: 20px; text-align: center;"&gt;Name of Employer&lt;/TD&gt;
      &lt;TD style="width: 430px; height: 20px; text-align: center;"&gt; Employer Address&lt;/TD&gt;
      &lt;TD style="width: 150px; height: 20px; text-align: center;"&gt;FROM&lt;/TD&gt;
      &lt;TD style="width: 150px; height: 20px; text-align: center;"&gt;TO&lt;/TD&gt;&lt;/TR&gt;
    &lt;TR class="row_to_clone_fw_emp"&gt;
      &lt;TD style="width: 310px; height: 20px; text-align: center;"&gt;&lt;label&gt;
        &lt;input type="text" id="fwemployer" name="fwemployer[]" style="width:300px"/&gt;
      &lt;/label&gt;&lt;/TD&gt;
      &lt;TD style="width: 430px; height: 20px; text-align: center;"&gt;
      &lt;input type="text" id="fwempaddress" name="fwempaddress[]" style="width:100%"/&gt;&lt;/TD&gt;
      &lt;TD style="width: 150px; height: 20px; text-align: center;"&gt;
  &lt;?php 
        include('calendar/classes/tc_calendar.php');
        $date3_default = "2013-10-14";
        $date4_default = "2013-10-20";
        $myCalendar = new tc_calendar("datefrom", true, false);
        $myCalendar-&gt;setIcon("calendar/images/iconCalendar.gif");
        $myCalendar-&gt;setDate(date('d', strtotime($date3_default))
              , date('m', strtotime($date3_default))
              , date('Y', strtotime($date3_default)));
        $myCalendar-&gt;setPath("calendar/");
        $myCalendar-&gt;setYearInterval(1970, 2020);
        $myCalendar-&gt;setAlignment('left', 'bottom');
        $myCalendar-&gt;setDatePair('datefrom', 'dateto', $date4_default);
        $myCalendar-&gt;writeScript();         
  ?&gt;        
  
      &lt;/TD&gt;
      &lt;TD style="width: 150px; height: 20px; text-align: center;"&gt; 
           &lt;?php
              $date3_default = "2013-10-14";
              $date4_default = "2013-10-20";
              $myCalendar = new tc_calendar("dateto", true, false);
          $myCalendar-&gt;setIcon("calendar/images/iconCalendar.gif");
          $myCalendar-&gt;setDate(date('d', strtotime($date4_default))
                , date('m', strtotime($date4_default))
                , date('Y', strtotime($date4_default)));
          $myCalendar-&gt;setPath("calendar/");
          $myCalendar-&gt;setYearInterval(1970, 2020);
          $myCalendar-&gt;setAlignment('left', 'bottom');
          $myCalendar-&gt;setDatePair('datefrom', 'dateto', $date3_default);
          $myCalendar-&gt;writeScript();  
  
           ?&gt;
  
      &lt;/TD&gt;
    &lt;/TR&gt;
    &lt;/TBODY&gt;
  &lt;/TABLE&gt;
  &lt;input type="submit" name="Submit" value="Submit" /&gt;
  &lt;/form&gt;
  &lt;INPUT type="button" value="Add Row" onclick="addRowfwemp(); return false;"/&gt;
  &lt;/DIV&gt;
  </code></pre>
  
  <p>the function called onclick is this:</p>
  
  <pre><code>function addRowfwemp() {
      /* Declare variables */
      var elements, templateRow, rowCount, row, className, newRow, element;
      var i, s, t;
  
      /* Get and count all "tr" elements with class="row".    The last one will
       * be serve as a template. */
      if (!document.getElementsByTagName)
          return false; /* DOM not supported */
      elements = document.getElementsByTagName("tr");
      templateRow = null;
      rowCount = 0;
      for (i = 0; i &lt; elements.length; i++) {
          row = elements.item(i);
  
          /* Get the "class" attribute of the row. */
          className = null;
          if (row.getAttribute)
              className = row.getAttribute('class')
          if (className == null &amp;&amp; row.attributes) {    // MSIE 5
              /* getAttribute('class') always returns null on MSIE 5, and
               * row.attributes doesn't work on Firefox 1.0.    Go figure. */
              className = row.attributes['class'];
              if (className &amp;&amp; typeof(className) == 'object' &amp;&amp; className.value) {
                  // MSIE 6
                  className = className.value;
              }
          } 
  
          /* This is not one of the rows we're looking for.    Move along. */
          if (className != "row_to_clone_fw_emp")
              continue;
  
          /* This *is* a row we're looking for. */
          templateRow = row;
          rowCount++;
      }
      if (templateRow == null)
          return false; /* Couldn't find a template row. */
  
      /* Make a copy of the template row */
      newRow = templateRow.cloneNode(true);
  
      /* Change the form variables e.g. price[x] -&gt; price[rowCount] */
      elements = newRow.getElementsByTagName("input");
      for (i = 0; i &lt; elements.length; i++) {
          element = elements.item(i);
          s = null;
          s = element.getAttribute("name");
          if (s == null)
              continue;
          t = s.split("[");
          if (t.length &lt; 2)
              continue;
          s = t[0] + "[" + rowCount.toString() + "]";
          element.setAttribute("name", s);
          element.value = "";
      }
  
      /* Add the newly-created row to the table */
      templateRow.parentNode.appendChild(newRow);
      return true;
  }
  </code></pre>
  
  <p>i am using this date picker for my script: 
  i am using the "Date Pair Example" on belows link.
  <a href="http://www.triconsole.com/php/calendar_datepicker.php" rel="nofollow">http://www.triconsole.com/php/calendar_datepicker.php</a></p>
  
  <p>thank u very much in advance ...</p>