0

How to call a javascript function in struts displaytag, i want to pass id into that javascript function.Iam not getting any idea any one help me..

<display:column style="text-align: center;" title="Booth No"
        property="partNo" />

here how can i call javascript function..

here is my code..

<div >
            <display:table id="boothResultsTableId"
                 name="${boothResult.perWiseboothResults}"
                defaultorder="ascending" defaultsort="4"
                style="width:auto;margin-left:1px;border:1px solid #C4DEFF;">

            <display:column style="text-align:center;" title="Polling % Range"
                    property="location" />
            <display:column style="text-align:center;" title="Total No of Booths"
                    property="votesEarned">
                    <div class="coverAll" 
                        onclick="alert('hi');">
                    </div>
            </display:column>
            <display:column style="text-align:center;" title="Party Votes %"
                    property="percentage" />
            </display:table>
            </div>
sakar
  • 243
  • 2
  • 7
  • 17

3 Answers3

0

Call a javascript function WHEN ? When clicked ?

JSP

<display:column style="text-align: center;" title="Booth No" property="partNo" />
   <div class="coverAll" 
       onclick="alert('hi ! ID is ' + <s:property value="#attr.myTab.myId" />);">
      stuff inside the div
   </div>
</display:column>

CSS

.coverAll{
   width: 100%;
   height: 100%;
}
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
0

<display:column style="text-align: center;" title="Booth No" property="partNo" />
<a onclick="fn(${row.id})">link</a>
</display:column>

where row is from <display:table id="row" ...

Alex
  • 11,451
  • 6
  • 37
  • 52
0

Although I am new to STRUTS I read Andrea's post and used the #attr. value idea. This may be a hackers way of doing it, but it worked.

This is my <display.column code:

<display:column class="textBold8" property="supplierCd" style="color:black"
    paramId="supplierCd" paramProperty="supplierCd" titleKey="supplier.supplierCd"
    sortable="true" href="javascript:openSmallWin(\'#attr.supplier.supplierId\');//">
</display:column>

This is my javascript code:

function openSmallWin(s) {
    // The value of 's' is selected using a .substring method in order to isolate the    actual
    // value of the supplier code. What comes into the javascript function is 
    // '?supplierCd=xxxxxxxxx#attr.supplier.suplierId'.
    // Where xxxxxxxxx is the actual value of the Supplier Code. Sorry.     
    var theUrl = "<%=request.getContextPath()%>/supplier.do? method=view&supplierCd="+s.substring(12,21);
    window.open(theUrl,"purchaseOrderWnd", 'resizable=1,scrollbars=1,width=800,height=675')
}
Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130