As I mentioned earlier my JSP page contains JavaScript URL
which is nothing but Linked List node. and each node contains more then one row.
So I tried to use JavaScript array to pass the values back to JavaScript function.
Now the problem is
regardless of iteration my function always displays the last value in the array
(Example if I have 2 rows in my array
as for i =0
id =4, grp = HOCKEY sname= John
and for i=1
id = 7 grp = SOCKER sname = Phil)
when I get back the value in my function it displays
ID =7
GRP = SOCKER
NAME = Phil
instead of this
ID =4
GRP = HOCKEY
NAME = John
ID =7
GRP = SOCKER
NAME = Phil
and it is because Linked List node (name) is out side of the for loop.
I want to get 'n' number of rows back when user clicks the link
But i am not sure how to achieve that.
Thanks in advance.
Here is the code snippet using javascript and hidden field
if(iterator.hasNext())
{
String name = (String)iterator.next();
LinkedList result = (LinkedList)hMap.get(name);
%>
<tr>
<td width="30%">
<%
for(int i=0; i<result.size();i++)
{
ParentBean parentBean = (ParentBean)result.get(i);
ChildBean childBean = (ChildBean)parentBean.getCommObj();
%>
<a href="JavaScript:selectProgram(id[<%= i%>] = new Array('<%= childBean.getStudentId()%>'),
grp[<%= i%>] = new Array('<%= childBean.getGroupId()%>'),
sname[<%= i%>]= new Array('<%= childBean.getName()%>
'
);"
>
<% } %>
<b><%=name %></b>
<script>
var id = new Array();
var grp = new Array();
var sname = new Array();
function selectProgram(id,grp,sname) {
for (var i=0; i<id.length; i++) {
alert("Length :"+ id.length);
alert("ID :"+ id[i]);
alert("GRP :"+ grp[i]);
alert("NAME:"+ sname[i]);
document.test.id.value = id[i];
document.test.groupId.value = grp[i];
document.test.name.value = sname[i];
}
self.document.test.submit();
}
<form method="POST" name="test" ACTION="/servlet/Test" method="post" >
<input name=name type="hidden" value="">
<input name=id type="hidden" value="">
<input name=groupId type="hidden" value="">