I want to pass the Id of a record from the display tag table. So, I can pass the value of Id to next process ,which will be pass from javascript.
Now when I print out the varSearchId value, I always get the Id of the first record of the display tag table.
I just want to pass Id parameter value as hidden from the display according to requirement.
<display:table class="displayTable" id="ItemList"
name="${sessionScope.searchList}" pagesize="15"
defaultsort="2" defaultorder="ascending" sort="list">
<display:column class="colSearchIngName" property=Name"
title="Name" sortable="true" headerClass="sortable"/>
<display:column class="colSearchIngPName" property="Class Name"
title="Class Name" sortable="true" headerClass="sortable"/>
<display:column title="" media="html">
<a href="javascript:showWindow();">Add</a>
<input type="hidden" id="searchId" value="${ItemList.Id}" name="searchId"/>
</display:column>
</display:table>
function showWindow()
{
var varSearchId= document.getElementById("searchId").value;
alert(varSearchId);
//call another process passing the varSearchId value
}
You're assigning the same ID to all the inputs in the table, which results in invalid HTML. The browser is kind enough (?) to give you the first input with this ID instead of throwing an exception.
The code should be:
<a href="javascript:showWindow('${ItemList.id}');">Add</a>
<input type="hidden" id="searchId_${ItemList.id}" value="${ItemList.id}" name="searchId"/>
function showWindow(itemId) {
alert(itemId);
// call another process passing the itemId value
}
but the input field doesn't serve any purpose, so you might remove it completely.
Note that your naming is bad:
itemList
rather than ItemList
item
rather than ItemList
.