在php表单上添加多行日期

时间:2013-10-22 02:40:43

标签: php datepicker

我已经坚持了将近一个星期,

我一直试图在不重新加载页面的情况下向表单的某个部分添加多行, 我克隆了字段并将它们放在一个数组中,但问题是日期,它不能放在一个数组中......任何人都可以帮助我,非常感谢...谢谢。

这是我的代码:

的index.php

<DIV id="mainContent_pnlEmploymentHistory">
<form id="form1" name="form1" method="post" action="value.php">
<TABLE id="dataTable">
  <TBODY>
  <TR>
    <TD style="width: 310px; height: 20px; text-align: center;">Name of Employer</TD>
    <TD style="width: 430px; height: 20px; text-align: center;"> Employer Address</TD>
    <TD style="width: 150px; height: 20px; text-align: center;">FROM</TD>
    <TD style="width: 150px; height: 20px; text-align: center;">TO</TD></TR>
  <TR class="row_to_clone_fw_emp">
    <TD style="width: 310px; height: 20px; text-align: center;"><label>
      <input type="text" id="fwemployer" name="fwemployer[]" style="width:300px"/>
    </label></TD>
    <TD style="width: 430px; height: 20px; text-align: center;">
    <input type="text" id="fwempaddress" name="fwempaddress[]" style="width:100%"/></TD>
    <TD style="width: 150px; height: 20px; text-align: center;">
<?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->setIcon("calendar/images/iconCalendar.gif");
      $myCalendar->setDate(date('d', strtotime($date3_default))
            , date('m', strtotime($date3_default))
            , date('Y', strtotime($date3_default)));
      $myCalendar->setPath("calendar/");
      $myCalendar->setYearInterval(1970, 2020);
      $myCalendar->setAlignment('left', 'bottom');
      $myCalendar->setDatePair('datefrom', 'dateto', $date4_default);
      $myCalendar->writeScript();         
?>        

    </TD>
    <TD style="width: 150px; height: 20px; text-align: center;"> 
         <?php
            $date3_default = "2013-10-14";
            $date4_default = "2013-10-20";
            $myCalendar = new tc_calendar("dateto", true, false);
        $myCalendar->setIcon("calendar/images/iconCalendar.gif");
        $myCalendar->setDate(date('d', strtotime($date4_default))
              , date('m', strtotime($date4_default))
              , date('Y', strtotime($date4_default)));
        $myCalendar->setPath("calendar/");
        $myCalendar->setYearInterval(1970, 2020);
        $myCalendar->setAlignment('left', 'bottom');
        $myCalendar->setDatePair('datefrom', 'dateto', $date3_default);
        $myCalendar->writeScript();  

         ?>

    </TD>
  </TR>
  </TBODY>
</TABLE>
<input type="submit" name="Submit" value="Submit" />
</form>
<INPUT type="button" value="Add Row" onclick="addRowfwemp(); return false;"/>
</DIV>

名为onclick的函数是:

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 < 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 && 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 && typeof(className) == 'object' && 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] -> price[rowCount] */
    elements = newRow.getElementsByTagName("input");
    for (i = 0; i < elements.length; i++) {
        element = elements.item(i);
        s = null;
        s = element.getAttribute("name");
        if (s == null)
            continue;
        t = s.split("[");
        if (t.length < 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;
}

我在我的脚本中使用这个日期选择器: 我在下面的链接上使用“日期对示例”。 http://www.triconsole.com/php/calendar_datepicker.php

非常感谢你...

0 个答案:

没有答案