Reputation: 3117
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
}
Upvotes: 0
Views: 9234
Reputation: 1
I was having a requirement to pass the values to a java script. The below snippet helped me
<display:column title="Action" media="html"><a href="javascript:popupUploadForm('<c:out value="${row.accountno}" />','<c:out value="${row.certtype}" />');">print</a></display:column>
Where row is UID and accountno and certtype are properties of column
Upvotes: -2
Reputation: 692121
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
.Upvotes: 3