Learn how to a build a cloud-first strategyRegister Now


Getting which row a user clicked

Posted on 2004-11-02
Medium Priority
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 (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);
Question by:jkawah
  • 2
LVL 35

Expert Comment

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

Author Comment

ID: 12484260
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="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 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

tsunpo earned 750 total points
ID: 12489949
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

ID: 12539521
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


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
If anyone asked you to network diagram of the internet, it was drawn in the form of a fluffy cloud which further became known as cloud computing. Popularly cloud computing is defined as workloads that run over the internet in a commercial provider’s…
Integration Management Part 2
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

810 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