jkawah
asked on
Getting which row a user clicked
How do I capture the value of the fields in the row that the user clicks. All my attempts using javascript & JSP give me the same row no matter which one is actually clicked.
Sample code:
onclick="javascript:getRow Values(thi s);"
function getRowValues( itemClicked )
{
// the nodes are used to trace back to row clicked on.
var grandparent = menuitemClicked.parentNode .parentNod e.parentNo de.parentN ode;
var rowNode = null;
// Loop through all the columns in this row to get column values
for( var intIndex = 0; intIndex < grandparent.childNodes.len gth; intIndex++ )
{
rowNode = grandparent.childNodes[ intIndex ];
switch (rowNode.id){
case "fndSymColumn": getFieldValue(rowNode, "hdnFundNumber"); break;
.........
}
}
}
function getFieldValue( rowNode, strField ){
var hdnNode;
var hdnValue;
// Loop through all attributes of the column to get value
for( var x = 0; x < rowNode.attributes.length; x++ ) {
if( rowNode.attributes[x].node Name.toLow erCase() == 'datafld' ) {
hdnNode = document.getElementById(st rField);
hdnValue = rowNode.attributes[x].node Value;
hdnNode.setAttribute("valu e", hdnValue);
}
}
}
Sample code:
onclick="javascript:getRow
function getRowValues( itemClicked )
{
// the nodes are used to trace back to row clicked on.
var grandparent = menuitemClicked.parentNode
var rowNode = null;
// Loop through all the columns in this row to get column values
for( var intIndex = 0; intIndex < grandparent.childNodes.len
{
rowNode = grandparent.childNodes[ intIndex ];
switch (rowNode.id){
case "fndSymColumn": getFieldValue(rowNode, "hdnFundNumber"); break;
.........
}
}
}
function getFieldValue( rowNode, strField ){
var hdnNode;
var hdnValue;
// Loop through all attributes of the column to get value
for( var x = 0; x < rowNode.attributes.length;
if( rowNode.attributes[x].node
hdnNode = document.getElementById(st
hdnValue = rowNode.attributes[x].node
hdnNode.setAttribute("valu
}
}
}
Can you post a working example of your problem? With the HTML you are using?
ASKER
I could only give a screen shot to properly illustrate, but I don't know if I'm permitted to do that in this forum. The html goes something like this:
<thead>
</thead>
<tbody>
for (int i=rowStarting;i<rowEnding; i++)
{
// Display rows of account assets
////////////////////////// ////////// ////////
count = count + 1;
fundSymbol = acVO.getFundAt(i);
<tr id="fundInfoRow" class="container1" onmouseover="this.style.co lor=colorH i;" onmouseout="this.style.col or=colorLo ;">
<td class="fundlist0" onclick="ledgerGo('<%=fund Symbol%>') ;">
<b><%=fundSymbol%></b><spa n class="note">fundSymbol</s pan><br/>
</td>
<td id="oltColumn" style="text-align:center;" >
<button id="oltButton" type="button" onMouseover="showmenu(even t,linkset[ 0])"
onMouseout="delayhidemenu( )" class="buttonStyle">
</button>
<div id="popmenu" class="menuskin"
onMouseover="clearhidemenu ();highlig htmenu(eve nt,'on')"
onMouseout="highlightmenu( event,'off ');dynamic hide(event )">
</div>
</td>
</tr>
<tr class="container1" >
<td class="fundlist0" colspan="9" style="text-align:center;" >
<form name="transForm" action="<tmpl:prepurl" method="post">
<input type="hidden" name="hdnAcctNumber" value='<%=hdnAcctNumber%>' />
<input type="hidden" name="hdnIndex" value='<%=i%>'/>
<input type="hidden" name="hdnTranType" />
</form>
</td>
</tr>
<%
}
//endFor
%>
</tbody>
</table>
<thead>
</thead>
<tbody>
for (int i=rowStarting;i<rowEnding;
{
// Display rows of account assets
//////////////////////////
count = count + 1;
fundSymbol = acVO.getFundAt(i);
<tr id="fundInfoRow" class="container1" onmouseover="this.style.co
<td class="fundlist0" onclick="ledgerGo('<%=fund
<b><%=fundSymbol%></b><spa
</td>
<td id="oltColumn" style="text-align:center;"
<button id="oltButton" type="button" onMouseover="showmenu(even
onMouseout="delayhidemenu(
</button>
<div id="popmenu" class="menuskin"
onMouseover="clearhidemenu
onMouseout="highlightmenu(
</div>
</td>
</tr>
<tr class="container1" >
<td class="fundlist0" colspan="9" style="text-align:center;"
<form name="transForm" action="<tmpl:prepurl" method="post">
<input type="hidden" name="hdnAcctNumber" value='<%=hdnAcctNumber%>'
<input type="hidden" name="hdnIndex" value='<%=i%>'/>
<input type="hidden" name="hdnTranType" />
</form>
</td>
</tr>
<%
}
//endFor
%>
</tbody>
</table>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
George. Sorry for the late response. I had to find the solution using a workaround. If anyone is interested, I can explain, but it's a bit too detailed. I am not using struts. I will accept your answer so the question gets closed.