Link to home
Start Free TrialLog in
Avatar of jkawah
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:getRowValues(this);"

function getRowValues( itemClicked )
{
     // the nodes are used to trace back to row clicked on.
     var grandparent = menuitemClicked.parentNode.parentNode.parentNode.parentNode;
     var rowNode = null;

     // Loop through all the columns in this row to get column values
     for( var intIndex = 0; intIndex < grandparent.childNodes.length; 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].nodeName.toLowerCase() == 'datafld' ) {
           hdnNode = document.getElementById(strField);
           hdnValue = rowNode.attributes[x].nodeValue;
           hdnNode.setAttribute("value", hdnValue);
        }
   }
}
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you post a working example of your problem?  With the HTML you are using?
Avatar of jkawah
jkawah

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.color=colorHi;" onmouseout="this.style.color=colorLo;">
          <td class="fundlist0" onclick="ledgerGo('<%=fundSymbol%>');">
            <b><%=fundSymbol%></b><span class="note">fundSymbol</span><br/>            
          </td>
          <td id="oltColumn" style="text-align:center;">
            <button id="oltButton" type="button" onMouseover="showmenu(event,linkset[0])"
                onMouseout="delayhidemenu()" class="buttonStyle">
            </button>
            <div id="popmenu" class="menuskin"
                onMouseover="clearhidemenu();highlightmenu(event,'on')"
                onMouseout="highlightmenu(event,'off');dynamichide(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>
ASKER CERTIFIED SOLUTION
Avatar of tsunpo
tsunpo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jkawah

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.