You are viewing limited content. For full access, please sign in.

Question

Question

Get a value from the column in the random row.

asked on August 16, 2014

Hello Everybody,

Have another question about table manipulation on Forms. Is it possible to get a value from specific column in the random row on the click?

For example I have a table which consists of 3 columns and 5 rows. I'd like to copy a value from the second column of the third row when cursor/click hits column 1 of the that row.

Thank you, 

 

0 0

Answer

SELECTED ANSWER
replied on August 18, 2014

Ok, I have updated the code above and the jsFiddle link as well. I did though leave the "alert" in there so that it can be replaced with code to update whatever column they need to.

0 0

Replies

replied on August 18, 2014 Show version history

Here you go, http://jsfiddle.net/1j2zxvth/1/

 

<table align="center" id="tblData" border="1" style="cursor: pointer;">
   <tr>
       <td>R1C1</td>
       <td>R1C2</td>
       <td>R1C3</td>
    </tr>
    <tr>
        <td>R2C1</td>
        <td>R2C2</td>
        <td>R2C3</td>
    </tr>
    <tr>
        <td>R3C1</td>
        <td>R3C2</td>
        <td>R3C3</td>
    </tr>
    <tr>
        <td>R4C1</td>
        <td>R4C2</td>
        <td>R4C3</td>
    </tr>
    <tr>
        <td>R5C1</td>
        <td>R5C2</td>
        <td>R5C3</td>
    </tr>
</table>
<script>
var tbl = document.getElementById("tblData");
if (tbl != null) {
var c = tbl.rows[2].cells[1];
tbl.rows[0].cells[0].onclick = function() {getval(c);};
}

function getval(e) {
    var index_row = e.parentNode.rowIndex;
    var index_cell = e.cellIndex;
    if (index_row !== null && index_cell !== null){
        // did user click 1st column?
        if (index_cell == 0)
            // grab value of 2nd column of clicked row
            var cell_val = tbl.rows[index_row].cells[1].innerHTML;
            alert(cell_val);
    }
}
</script>

 

0 0
replied on August 18, 2014

I think you are close to what they are asking, but I think they want to be able to get the value of the current row so that they can get the value from a different column put into that column of the row. 

0 0
SELECTED ANSWER
replied on August 18, 2014

Ok, I have updated the code above and the jsFiddle link as well. I did though leave the "alert" in there so that it can be replaced with code to update whatever column they need to.

0 0
replied on August 18, 2014

Thank you Gentlemen,

Will test the code and reply with result, it looks like the solution.

Best Regards,

Vladimir

0 0
replied on August 22, 2014

Hi Vladimir, 

 

If your question has been answered, please let us know by clicking the "This answered my question" button on the response.

 

If you still need assistance with this matter, just update this thread. Thanks!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.