Note that there are some explanatory texts on larger screens.

plurals
  1. POonclick event get value from javascript function not working
    text
    copied!<p>I have this line </p> <pre><code>&lt;td&gt;&lt;a href="offer.php" onclick="location.href=this.href+'?key=' + getTableRow();return false;"&gt;&lt;xsl:value-of select="product_name"/&gt;&lt;/a&gt;&lt;/td&gt; </code></pre> <p>When i try to get the return value of the function getTableRow() and display it to href link i take key=undefined.Why happen that?</p> <p>This is my script on the head of html</p> <pre><code>&lt;script type="text/javascript"&gt; function getTableRow() { var rowIdx; var rowData= []; var selectedRow; var rowCellValue; if (!document.getElementsByTagName || !document.createTextNode) return; var rows = document.getElementById('products_table').getElementsByTagName('tbody')[0].getElementsByTagName('tr'); for (i = 0; i &lt; rows.length; i++) { rows[i].onclick = function() { rowIdx = this.rowIndex; selectedRow= this.cells; for(j= 0;j&lt;selectedRow.length;j++){ rowCellValue= selectedRow[j].textContent || selectedRow[j].innerText; rowData.push('cell '+j+': '+rowCellValue); } } } return "Row #" +rowIdx+'. '+ rowData[i]; } &lt;/script&gt; </code></pre> <p>I try many solution but nothing work..Please help..</p> <p>In the beginning the only thing i want is to return the rowIndex.Even in that i get undefined.Why happend that?My first code before i try to get the content from row that user select.</p> <pre><code>&lt;script type="text/javascript"&gt; var userSelect; function getTableRow() { if (!document.getElementsByTagName || !document.createTextNode) return; var rows = document.getElementById('products_table').getElementsByTagName('tbody')[0].getElementsByTagName('tr'); for (i = 0; i &lt; rows.length; i++) { rows[i].onclick = function() { userSelect = this.rowIndex; } } return userSelect; } &lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload