Home » Java » html,js:populate form fields with values from arraylist and save back this arraylist in servlet

html,js:populate form fields with values from arraylist and save back this arraylist in servlet

Posted by: admin August 11, 2018 Leave a comment

Questions:

I have an html form with textboxes and below that is a dynamically created table with an edit and delete hyperlink. When I click the edit link, the values corresponding to that row have to get populated in the corresponding textboxes so that the user can edit them. Below is the code for table generation:

<c:forEach var="row" items="${memberList}">
   <input type="hidden" name="chk" id="chk" value="${row.connectionName}" />
    <tr>

        <td><c:out value="${row.connectionName}"/> </td>
        <td><c:out value="${row.desc}"></c:out> </td>

        <td><a href="#" name="EditConn" id="EditConn">Edit</a><td>
        <td><a href="#" name="Delete" id="Delete">Delete</a> </td>
    </tr>
</c:forEach>

Sending memberList from servlet as request.setAttribute("memberList",memberList);.

I get the table values populated correctly. Now, in order to get values corresponding to a particular row (on edit click event) into their corresponding textboxes in the form, what can be done?

P.S. I tried using a hidden field near the edit link

    <td><a href="#" name="EditConn" id="EditConn" 
    onclick="fnGetName();">Edit</a>
    <input type="hidden" name="connFromList" id="connFromList" 
    value="${row.connectionName}" /><td>   

and tried to alert the connFromList value, but it was always giving me the first row value. Please help.

Answers: