Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring the index of a for loop in javascript
    primarykey
    data
    text
    <p>I'm developing an android app with phonegap. I'm making an HTML table with some that with a <code>for</code> loop from localStorage. I need, for each row, to store the index i of the <code>for</code> to use it for retrieving an item from localStorage that has the name like the index. I have some code but the variable that i defined for that effect gets overwritten by the loop (of course). Here's the code:</p> <pre><code>&lt;script language="javascript"&gt; if(len != 0) { var table = document.getElementById('hor-minimalist-b'); // get the table element var tableBody = table.childNodes[1]; // get the table body var tableHead = table.childNodes[0]; // get the table head var thead = document.createElement('th'); var row2 = document.createElement('tr'); // create a new row var headText = document.createTextNode('Dados'); thead.scope = "col"; thead.appendChild(headText); row2.appendChild(thead); tableHead.appendChild(row2); for (var i=0; i&lt;len; i++) { var row = document.createElement('tr'); // create a new row var cell = document.createElement('td'); // create a new cell var a = document.createElement('a'); var cellText = document.createTextNode(localStorage.getItem('key' + i)); var xyz = "key" + i; a.href = "alterar.html"; a.onclick = function() { doLocalStorage(xyz) }; a.appendChild(cellText); cell.appendChild(a); // append input to the new cell row.appendChild(cell); // append the new cell to the new row tableBody.appendChild(row); // append the row to table body }} &lt;/script&gt; &lt;/table&gt; </code></pre> <p>Maybe i'm not explaining myself too well. If you need any more info please ask. Thanks in advance. Eva</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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