0

I am trying to pull columns from a table if a checkbox was selected. Here is the table that contains the checkbox called 'selectedSched'

        <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" name="selectedSched"   
                                  value="<c:out value="${schedcombo}"/>"/>  
                        </td> 

                       <td id="ModifyScheduleNumber"><c:out value="${row.getSCHEDULE_NUMBER()}" /></td>
                       <td id="ModifyYear"><c:out value="${row.getEFT_CONTRACT_YEAR()}" /></td>
                       <td id="ModifyCreationDate"><c:out value="${row.getCREATION_DATE()}"/></td>
                       <td style="text-align: right; padding-right: 5px;"><c:out value="${row.getNUM_OF_PAY_RECORDS()}"/></td>
                       <td style="text-align: right; padding-right: 5px;"><c:out value="${schedTotl}"/></td>
                       <td><select style="width:45px;" size="1" id="ModifyStatus" name="ModifyStatus_<c:out value="${schedcombo}"/>" 
                                   class="combosmall">
                           <c:forEach items="${ModifyList}" var="statusValue">
                              <option value="${statusValue}"
                                <c:if test="${EFTstatus} = statusValue"> selected="selected"</c:if>
                                 >${statusValue}</option>
                           </c:forEach>
                       </select> </td>
                       <td>
                         <input style="width:85px" id="ModifyStatusDate" name="ModifyStatusDate_<c:out value="${schedcombo}"/>" 
                                type="text" class="texttable" value="${row.getSTATUS_DATE()}"/>
                       </td>
                       <td><c:out value="${row.getAPPR_HUD_EMPLOYEE()}"/></td>
                    </tr>
                    </c:forEach>

                   </tbody>

I am creating a function that is trying to compare the Creation date field to an input Status Date field. Here is my function call:

        $("#submitMEFTS").mouseup(function ()
                    {

                        for(var i=0; i<updateformID.selectedSched.length; i++)
                         {
                  if(updateformID.selectedSched[i].checked == true)
                              { 
                                var holdCreationDate = $('#ModifyCreationDate[i]').val();
                                var holdSchedule = $('#ModifyScheduleNumber[i]').val();
                                alert("The checked button was clicked");

                  } 
                              else
                              {
                                  alert("The checked button was not clicked") ;
                              }
                          }
                     });  

I have the selected check working but I am getting an error trying to use the 'ModifyCreationDate' field. Clearly just putting a '[i]' at the end is invalid. What is the proper way to pull the correct index of this field?

I know with a servlet call I had to do something similar to the ModifyStatus field to create different "names" for each row but wondering if there is a better/cleaner option.

Thanks again

hammerva
  • 129
  • 1
  • 14
  • Well, the # is for the ID. You're using the name attribute for this. http://stackoverflow.com/questions/9680037/how-do-i-select-an-element-with-its-name-attribute-in-jquery – Nikki9696 Feb 05 '16 at 20:01
  • Also, keep in mind that ID should be unique. If you're ending up with multiple elements with the same id, you should fix that. – Nikki9696 Feb 05 '16 at 20:02
  • So if I have a table and one of the columns has an ID of "ModifyDate" for example it isn't one element but multiple elements depending on the number of rows on the table? – hammerva Feb 05 '16 at 20:12
  • No, that works for the name property, but for ID, it's just invalid and will mess up some browsers and jquery selectors etc – Nikki9696 Feb 05 '16 at 20:27
  • https://developer.mozilla.org/en-US/docs/Web/API/Element/id "The Element.id property represents the element's identifier, reflecting the id global attribute. It must be unique in a document, and is often used to retrieve the element using getElementById. " – Nikki9696 Feb 05 '16 at 20:28
  • I mention this because I believe this creates a loop that makes you repeat your rows. If that's not the case, sorry about that =) You can check by viewing the source html after the jsp has finished rendering it. – Nikki9696 Feb 05 '16 at 20:30
  • Well I can't create a name in a unless I make it a input box inside of it. Even with that I had to uniquely define the name of the field for every row in the servlet. So it looks like I need to do the same thing for the ID. Seems that when you have a check or select box inside a table, the only purpose of an array is to check the checkbox because every cell in the table has a different name or ID. – hammerva Feb 07 '16 at 03:18

0 Answers0