Click on row with JS
<p>I have a JavaScript which I use to open a new page when I click on table row:</p>

<pre><code>//for clicking on a row in tabs and opening new page
function addOnclickToTabsDatatableRows() {
    //gets all the generated rows in the html table
    var trs = document.getElementById('formname:dataTable').getElementsByTagName('tbody')[0]
    .getElementsByTagName('tr');
    //on every row, add onclick function (this is what you're looking for)
    for (var i = 0; trs.length &gt; i; i++) {
        var cells = trs[i].cells;                    
        for(var j=1; j &lt; cells.length; j++){
            cells[j].onclick = new Function("rowOnclick(this.parentElement)");
        }                    
    }
}
</code></pre>

<p>I noticed a problem which I cannot solve. I apply this JS script on several pages. Into every page I have a different forms with different Ids. Now if I want to use this JS I have to have every form with id <code>formname</code>. How I can apply this JS for every form no matter what Id is there? Is there any standard approach that I can use? </p>
