javascript dynamic foam field with [+] to select dates from calendar

<script language="javascript">
        function insertRow(no, max_row) {
                var thisRow = document.all.ddarTable.insertRow(no);
                var thisCell = thisRow.insertCell();
                var cellHTML = "<%= ddarform.HANDLEDUSER %>";
                thisCell.innerHTML =cellHTML;
                thisCell = thisRow.insertCell();
                thisCell.innerHTML = "<input type='textbox' name='handledUser[]' maxlength='30' size='30'>";
                thisCell = thisRow.insertCell();
                thisCell.innerHTML = "<%= ddarform.HANDLEDDATE %>";
                thisCell = thisRow.insertCell();
                thisCell.innerHTML = "<input type='textbox' name='handledDate[]' maxlength='30' size='30'><input style='font-size:11px' type=button value=\"set\" onclick='popUpCalendar(this, forms[0].elements[\"handledDate[]\"], \"yyyy-mm-dd\")'>";
                thisCell = thisRow.insertCell();
                rebuildIdx();
        }
</script>

<input type="textbox" name="handledDate[]" maxlength="30" size="30">
<input style='font-size:11px' type=button value="set" onclick='popUpCalendar(this, forms[0].elements["handledDate[]"], "yyyy-mm-dd")'>
<a href="javascript:insertRow(1, 2)">[+]</a>

popup 唔到calendar,可以點?

[ 本帖最後由 850t 於 2009-9-2 15:14 編輯 ]

出乜 error?

TOP

finally it works!! reference to others...
        function insertHandledRow(no, limit) {
                var limit_size = document.forms[0].elements["handledUser[]"];
                if (limit <= limit_size.length)
                        return;
                var thisRow = document.all.handled.insertRow(no);
                var thisCell = thisRow.insertCell();
                var cellHTML = "<%= ddarform.HANDLEDUSER %>";
                thisCell.innerHTML =cellHTML;
                thisCell = thisRow.insertCell();
                thisCell.innerHTML = "<input type='textbox' name='handledUser[]' maxlength='30' size='30'>";
                thisCell = thisRow.insertCell();
                thisCell.innerHTML = "<%= ddarform.HANDLEDDATE %>";
                thisCell = thisRow.insertCell();
                thisCell.innerHTML = "<input type='textbox' name='handledDate[]' maxlength='30' size='30'><input style='font-size:11px' type=button value=\"set\" onclick='popUpCalendar(this, forms[0].elements[\"handledDate[]\"], \"yyyy-mm-dd\")'>";
                thisCell = thisRow.insertCell();
                rebuildIdx();
        }

        <table id="handled" border="0" width="100%">
    <tr>
        <td nowrap="nowrap"><%= ddarform.HANDLEDUSER %></td>
                <td><input type="textbox" name="handledUser[]" maxlength="30" size="30"></td>
                <td nowrap="nowrap"><%= ddarform.HANDLEDDATE %></td>
                <td><input type="textbox" name="handledDate[0]" maxlength="30" size="30"><input style='font-size:11px' type=button value="set" onclick='popUpCalendar(this, forms[0].elements["handledDate[0]"], "yyyy-mm-dd")'>
                    <a href="javascript:insertHandledRow(1,2)">[+]</a>
                </td>
        </tr>
        </table>

now I need to figure out how to pass the handledDate array to struts...

TOP

原帖由 850t 於 2009-9-2 17:40 發表
now I need to figure out how to pass the handledDate array to struts

You just need to set the name of those inputs to the same name.
Then set the type of the field in the ActionForm in struts to array type, then the data will can be passed to struts in the order you defined those inputs.
says
  1. <input name="strList" />
  2. <input name="strList" />
  3. <input name="strList" />
  4. <input name="strList" />
複製代碼
then in ActionForm
  1. private String[] strList
  2. public String[] getStrList() {
  3. return strList;
  4. }
  5. public void setStrList(String[] in) {
  6. strList = in;
  7. }
複製代碼

TOP

我試過,但我個popupCalendar個jaavscript又唔識認,要用
<input type="textbox" name="handledDate[0]" maxlength="30" size="30"><input style='font-size:11px' type=button value="set" onclick='popUpCalendar(this, forms[0].elements["handledDate[0]"], "yyyy-mm-dd")'>
所以。。。

TOP

回覆 5# 的帖子

d input 個 name set 一樣
再 set 一個獨立 id 比 d input 得唔得?
  1. <input id="strList[0]" name="strList" />
  2. <input id="strList[1]" name="strList" />
  3. <input id="strList[2]" name="strList" />
  4. <input id="strList[3]" name="strList" />
複製代碼

TOP

error :
javax.servlet.ServletException: BeanUtils.populate
        org.apache.struts.util.RequestUtils.populate(RequestUtils.java:497)


java.lang.NullPointerException
        org.apache.commons.beanutils.PropertyUtils.setIndexedProperty(PropertyUtils.java:1334)
        org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:913)

javascript:
        function insertHandledRow(no, limit) {
                var limit_size = document.forms[0].elements["handledUser[]"];
                if (limit <= limit_size.length)
                        return;
                var thisRow = document.all.handled.insertRow(no);
                var thisCell = thisRow.insertCell();
                var cellHTML = "<%= ddarform.HANDLEDUSER %>";
                thisCell.innerHTML =cellHTML;
                thisCell = thisRow.insertCell();
                thisCell.innerHTML = "<input type='textbox' name='handledUser[]' maxlength='30' size='30'>";
                thisCell = thisRow.insertCell();
                thisCell.innerHTML = "<%= ddarform.HANDLEDDATE %>";
                thisCell = thisRow.insertCell();
                thisCell.innerHTML = "<input type='textbox' name='handledDate[]' maxlength='30' size='30'><input style='font-size:11px' type=button value=\"set\" onclick='popUpCalendar(this, forms[0].elements[\"handledDate[]\"], \"yyyy-mm-dd\")'>";
                thisCell = thisRow.insertCell();
                rebuildIdx();
        }

my code:
<table id="handled" border="0" width="100%">
    <tr>
        <td nowrap="nowrap"><%= ddarform.HANDLEDUSER %></td>
                <td><input type="textbox" name="handledUser[]" maxlength="30" size="30"></td>
                <td nowrap="nowrap"><%= ddarform.HANDLEDDATE %></td>
                <td><input type="textbox" name="handledDate[0]" maxlength="30" size="30"><input style='font-size:11px' type=button value="set" onclick='popUpCalendar(this, forms[0].elements["handledDate[0]"], "yyyy-mm-dd")'>
                    <a href="javascript:insertHandledRow(1,2)">[+]</a>
                </td>
        </tr>
        </table>

TOP

to this:
javascript:
                thisCell.innerHTML = "<input type='textbox' id='strHandledDate[]' name='handledDate' maxlength='30' size='30'><input style='font-size:11px' type=button value=\"set\" onclick='popUpCalendar(this, forms[0].elements[\"handledDate[]\"], \"yyyy-mm-dd\")'>";

code:
                <td><input type="textbox" id="strHandledDate[0]" name="handledDate" maxlength="30" size="30"><input style='font-size:11px' type=button value="set" onclick='popUpCalendar(this, forms[0].elements["strHandledDate[0]"], "yyyy-mm-dd")'>

also return the same error

TOP