Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's not the right way to do it, but a simple solution would be use <code>addEventListener</code> instead <code>onload</code>:</p> <pre><code>&lt;%int number=0;%&gt; &lt;c:forEach var="row" items="${tAdmin.rows}" varStatus="totalRow" step="1"&gt; &lt;td&gt;&lt;%=++number%&gt;&lt;/td&gt; &lt;td&gt; &lt;div id="content&lt;%=number%&gt;" style="table-layout:fixed; width:405px; word-wrap:break-word;"&gt; &lt;script language="JavaScript" type="text/JavaScript"&gt; window.addEventListener("load", function () { var element = document.getElementById("content&lt;%=number%&gt;"); element.innerHTML=Utf8.decode('${row.content}'); }, true); &lt;/script&gt; &lt;/div&gt; &lt;/td&gt; &lt;/c:forEach&gt; </code></pre> <p>In fact your code is using only the last "onload" because, when loading the page, it will execute the javascript <code>load</code> callback only when finish full loading it. So, each time you loop is executed, it updates the <code>load</code> callback reference for the last one, so when <code>onload</code> is triggered, the last only will be executed.</p> <p>But your code has other errors too. The <code>content</code> id, repeats at the code lot of times, that will make your div <code>getElementById</code> useless, because you have lot of ids that are equal. Ids must be unique to work property.</p> <p>To finish, it's not a good pattern to mix your HTML with scripts inside, is better to have you logic file (javascript file) outside, then it can make changes in your code when finish to load, reading the html that was generated. You also can create <code>data</code> attribute in your <code>div</code> then read it by the javascript to manage all itens with a specific <code>data</code> attributes. </p> <p>To keep it simple, I will add an example:</p> <pre><code>&lt;%int number=0;%&gt; &lt;c:forEach var="row" items="${tAdmin.rows}" varStatus="totalRow" step="1"&gt; &lt;td&gt;&lt;%=++number%&gt;&lt;/td&gt; &lt;td&gt; &lt;div id="content&lt;%=number%&gt;" style="table-layout:fixed; width:405px; word-wrap:break-word;" data-content="${row.content}"&gt; &lt;/div&gt; &lt;/td&gt; &lt;/c:forEach&gt; </code></pre> <p>Now the script file (I'm using jQuery for this example works on any browser):</p> <pre><code>$(function() { $("[data-content]").each(function(item) { $(item).html(Utf8.decode(item.attr('data-content'))); }); }); </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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