如何在同一页面上的onload表单后获取动态表的值

时间:2015-02-02 11:04:02

标签: javascript jsp struts2

您好我已经使用ADD重置删除按钮创建了动态表。当我在同一页面上提交表单并重新加载时,我也没有获得我输入的值。我正在检查验证,所以当它检查验证并进入同一页面时我没有得到值。所以我没有得到place_from_0,place_to_0,resident_address_0,resident_Dist_headqua_0这些新增行的文本字段

 <BODY bgcolor="#B7CCDF"  onload="callRowResident();">


 <tr>
                                    <input type="hidden" name="num4" id="num4"/>
                                    <input type="hidden" name="tblResidentParticularData" id="tblResidentParticularData"/>
                                    <input type=hidden name="rowsCount8" id="rowsCount8" style='width:160px; text-align: left'/>
                                    <td>
                                <table id="residentParticular" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="70%">

                                     <tr>
                                        <td valign=middle align=center><input type="checkbox" name="chk"/></td>
                                        <td align="center"><table><tr><td><s:textfield name="place_from_0" id="place_from_0" maxlength="15" style="width:150px;"  readonly="true" onblur="checkfromcurrentdate('0'),checktocurrentdatefrom('0')" /></td><td><a href="javascript:NewCssCal('place_from_0','ddmmyyyy')"> <img src="Images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></td></tr></table></td>
                                        <td align="center"><table><tr><td><s:textfield name="place_to_0" id="place_to_0" maxlength="15" style="width:150px;"  readonly="true" onblur="checktodateplace('0'),checktocurrentdate('0')"/></td><td><a href="javascript:NewCssCal('place_to_0','ddmmyyyy')"> <img src="Images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></td></tr></table></td>
                                         <td align="center"><s:textarea rows="2" id="resident_address_0" name="resident_address_0" style="width:470px;height:45px;"></s:textarea></td>
                                        <td align="center"><s:textfield  name="resident_Dist_headqua_0" id="resident_Dist_headqua_0"  style="width:350px;"  onblur = "isIllegalString(this)"/></td>

                                     </tr>




                                 <table  width="70%">
                                        <tr>
                                            <td>
                                                <table align="center"><tr>
                                                    <td valign=middle align=center><INPUT type="button" class="pagetitle" value="ADD ROW" onclick="addRowResident('residentParticular');" /></td>
                                        <td valign=middle align=center><INPUT type="button" class="pagetitle" value="DELETE ROW" onclick="deleteRow('residentParticular');" /></td>
                                        <td valign=middle align=center><INPUT type="button" class="pagetitle" value="RESET" onclick="resetRows('residentParticular');" /></td>
                                                </tr></table>
                                            </td>



                                        </tr>
                                  </table> </table>
                                     </td>
                                  </tr> 

的.js

 function callRowResident()
 {
 var myVar =eval('<%=request.getAttribute("resident")%>');

    for(var i=1;i<myVar;i++)
 {

  addRowResident('residentParticular');
}

}

 var num4 = 0;

 function addRowResident(tableID) {

 //alert("inside RowResident");
  num4 = num4 + 1;
      var table = document.getElementById(tableID);
     //  alert("rowCount"+table);
     rowCount = table.rows.length;
    // alert("myVar..."+rowCount);
     myVar=rowCount;
     document.getElementById("tblResidentParticularData").value=rowCount;

     // alert("myVar..."+myVar);
      //rowCount=3;
      var row = table.insertRow(rowCount);

      var cell1 = row.insertCell(0);
      //cell1.innerHTML="My Cell Added";

      var element1 = document.createElement("input");
      element1.type = "checkbox";
      element1.align = "center";
      cell1.appendChild(element1);


      var cell2 = row.insertCell(1);
      var element2 = document.createElement("td");
      element2.innerHTML = "<td valign=middle align=center><input type='text' name=place_from_"+num4+" id=place_from_"+num4+" readonly='true' style='width:150px;' onblur='checkfromcurrentdate("+num4+"),checktocurrentdatefrom("+num4+")''/><a href=\"javascript:NewCssCal('place_from_"+num4+"','ddmmyyyy'); \"> <img src=\"Images/cal.gif\" width=16 height=16 border=0 alt=\"Pick a date\"></a></td>"
      element2.align = "center";
      cell2.appendChild(element2);

      var cell3 = row.insertCell(2);
      var element3 = document.createElement("td");
      element3.innerHTML = "<td valign=middle align=center><input type='text' name=place_to_"+num4+" id=place_to_"+num4+" readonly='true' style='width:150px;' onblur='checktodateplace("+num4+"),checktocurrentdate("+num4+")'/><a href=\"javascript:NewCssCal('place_to_"+num4+"','ddmmyyyy'); \"> <img src=\"Images/cal.gif\" width=16 height=16 border=0 alt=\"Pick a date\"></a></td>"
      element3.align = "center";
      cell3.appendChild(element3);


      var cell4 = row.insertCell(3);
      var element4 = document.createElement("td");
      element4.innerHTML = "<textarea rows=3 id=resident_address_"+num4+" name=resident_address_"+num4+" style=\"width:470px;height:45px;\" onblur=\"isIllegalString(this)\"></textarea>"
      element4.align = "center";
      cell4.appendChild(element4);

      var cell5 = row.insertCell(4);
      var element5 = document.createElement("td");
      element5.innerHTML = "<td valign=middle align=center><input type='text' name=resident_Dist_headqua_"+num4+" id=resident_Dist_headqua_"+num4+" style='width:350px; text-align: left' onblur = 'isIllegalString(this)'/> </td>"
      element5.align = "center";
      cell5.appendChild(element5);

      document.getElementById('rowsCount8').value=num4;

}

所以请给我解决方法如何获得价值或如何使用动作类。

0 个答案:

没有答案