Wednesday, 18 September 2013

Accessing specific member of an ArrayList using Javascript

Accessing specific member of an ArrayList using Javascript

So, I have a table in a jsp page which shows the data fetched from a
database via an ArrayList forwarded to the page. Each row of the table has
a radio button corressponding to it. Now, I would like to access the
elements in the row (the ArrayList's members on the selection of the
corresponding radio button and then click of an 'edit' button) Any
thoughts as to how to achieve this would be very much appreciated. Here's
my code for a bit intro.
<%
ArrayList<requestbean> reqjsp = new ArrayList<requestbean>();
reqjsp = (ArrayList<requestbean>) (request.getAttribute("reqdb"));
%>
<script type ="text/javascript">
function x()
{
var ele = document.getElementsByName('reqradio');
var i = ele.length;
for (var j = 0; j < i; j++)
{
if (ele[j].checked)
{
document.getElementById("edireq").disabled = false;
alert('request '+(j+1)+' selected');
//Here is where the functionality is desired to access
reqjsp.get(j)
}
}
}
</script>
<input type="button" name="edireq" id="edireq" onclick="x()" value="Edit
Request">
These are a few columns in my table.
<%
for(int i=0;i<reqjsp.size();i++)
{
%>
<tr>
<td> <input type="radio" name="reqradio" id="req<%=(i+1) %>"></td>
<td><%= reqjsp.get(i).getRequestid() %></td>
<td><%= reqjsp.get(i).getRequestor() %></td>
<td><%= reqjsp.get(i).getApprover() %></td>
</tr>
<%} %>

No comments:

Post a Comment