Getting which row a user clicked

Posted on 2004-11-02
Last Modified: 2012-06-27
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:


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 ({
            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);
Question by:jkawah
    LVL 35

    Expert Comment

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

    Author Comment

    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:

    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=";" onmouseout=";">
              <td class="fundlist0" onclick="ledgerGo('<%=fundSymbol%>');">
                <b><%=fundSymbol%></b><span class="note">fundSymbol</span><br/>            
              <td id="oltColumn" style="text-align:center;">
                <button id="oltButton" type="button" onMouseover="showmenu(event,linkset[0])"
                    onMouseout="delayhidemenu()" class="buttonStyle">
                <div id="popmenu" class="menuskin"
            <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"         />

    Accepted Solution

    It seems u always have the same form ("transForm") with the same field names ("hdnAcctNumber", "hdnIndex"...)
    No matter which column u choose...

    >                 <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>

    How about use "multibox" and give each field different names:

    I am using Struts... My idea is sth like this: Give each field different names in a single "ActionForm"
    Then use multibox to get which column the user clicks and retrive the specific field name from the form...
    (if u don need multiple options than skip the "multibox" thing)

          <html:form action="/xxx/xxx">
            <c:forEach var="i" begin="rowStarting" end="rowEnding">
                <td><html:multibox property="selectedItems" value="${i}"/></td>
                <td><html:hidden property="hdnAcctNumber${i}" value="${hdnAcctNumber}"/></td>

    Sorry that I can only explain it in my own way, but hope the idea helps  :)

    Author Comment

    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.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Digital marketing agencies have encountered both the opportunities and difficulties that emerge from working with a wide-ranging organizations.
    For Sennheiser, comfort, quality and security are high priority areas. This paper addresses the security of Bluetooth technology and the supplementary security that Sennheiser’s Contact Center and Office (CC&O) headsets provide.  
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now