jeudi 25 février 2016

Update a checkbox value in table correctly in JSP

I am trying to put an edit in my processing that sets a checkbox field 'checked' in a table. here is my layout of the table:

      <table id="checkedTable" >
         <thead>
           <tr>
            <th>  SEL</th>
            <th>Schedule Number</th>
            <th>Contract Year</th>
            <th>Creation Date</th>
            <th>Num of Pay Recs</th>
            <th>Schedule Total</th>
            <th>Status</th>
            <th>Status Date</th>
            <th>Approval ID</th>
          </tr>
          </thead>
            <tbody style="overflow-y: scroll; ">
               <c:forEach  var="row" items="${Updresults}">
               <c:set var="sched" value="${row.getSCHEDULE_NUMBER()}" />
               <c:set var="eftyear" value="${row.getEFT_CONTRACT_YEAR()}" />
               <c:set var="EFTstatus" value="${row.getSTATUS()}" />
               <c:set var="schedcombo"  value="${sched}${eftyear}" />
               <fmt:formatNumber var="schedTotl" value="${row.getTOTAL_AMOUNT()}" pattern="$##,###,##0.00"/>
               <tr>
                  <td align="center">  
                  <input style="width:50px;" type="checkbox" id="selectedSched" 
                         name="selectedSched" 
                         value="<c:out value="${schedcombo}"/>"/>  
                 </td> 

                </c:forEach>

         </tbody>
      </table>

Here is my javascript code in the window onLoad processing:

     for(var i=0; i<updateformID.selectedSched.length; i++)
           {

              var checkSchedule = document.getElementById("checkedTable").rows[i + 1].cells[1].innerHTML;
              var checkYear = document.getElementById("checkedTable").rows[i + 1].cells[2].innerHTML;
              $('#holdLineSchedule').val(checkSchedule); 

              for(var j=0; j<selectObject.listSched.length; j++)
                  {
                     var itemSchedule =  selectObject.listSched[j].schedulekey;
                     var itemContractYear = selectObject.listSched[j].contractkey ;
                     if (checkSchedule === itemSchedule)
                        {
                          alert("Schedule Number" + itemSchedule + " is found in process") ;
                          j = selectObject.listSched.length + 1  ;

                          document.getElementById("selectedSched").rows[i + 1].checked = true;

                         }

              }

The processing is having a problem with trying to update the 'checked' property to 'true' with an error on the 'rows[i + 1]' part. Am I missing something in the document.getElementbyID to use the 'checked' attribute.

I know one way of figuring this out is to use the 'name' of the checkbox field but then I have a problem with my servlet because I am doing a 'request.getParameterValues("selectedSched")' to loop through all the records checked. I don't know if there is a way to use 'getParameterValues' by ID instead of the name in servlet.

Thanks again.




Aucun commentaire:

Enregistrer un commentaire