Note that there are some explanatory texts on larger screens.

plurals
  1. POdecode and encode HTML from php htmlentities in real time using jQuery
    text
    copied!<p>Well this is the problem, i have a "pre" tag with encoded html using htmlentities() from php that shows correctly on website.</p> <p>But then i want to redecode it to put it in a "textarea" to work with in real time. (like stackoverflow does for example). And then this text modified is encoded (again and again) in the "pre" tag with the new info.</p> <p>I tried this but it seems that it doesnt work, because the textarea is allways empty. This is the code:</p> <pre><code>&lt;script&gt; var t0=document.getElementById("textarea0"), x0=document.getElementById('pre0'); t0.value=x0.innerHTML().html().text(); //dec t0.onkeyup=function(){ x0.innerHTML=t0&gt;.value.text().html(); //enc}; &lt;/script&gt; </code></pre> <p>i dont really understand how this code works, i know is wrong because jquery is far away from my mind, i saw others similar questions related to this using <code>$('&lt;div/&gt;')</code> before encoding but I dont think that was the problem. (i repeat that i am blind on this)</p> <p>(sorry if i do too many mistakes, im not english writer as you can guess, and im not using translators)</p> <p><strong>EDITED</strong></p> <p>Well first part works now, Textarea is filled with the content of the PRE and is decoded (with <code>&lt;&gt;</code>and that kind of things) for real work.</p> <p>But i cant give it back to the PRE, putting them the new changes.</p> <p>this is the actual code now:</p> <pre><code>var t0=$("textarea#textareaName0"), x0=$('pre#xmpName0'); t0.val(x0.text()); //dec t0.keyup(function() { x0.innerHTML=t0.val(); //enc }); </code></pre> <p>Any solution? (thank you so much)</p> <p><strong>Final Solution</strong></p> <p>In order to update content the code which work is:</p> <pre><code>t0.keyup(function() { x0.text(t0.val()); //enc }); </code></pre> <p>As you said, jquery can print on screen HTML without been interpreted so i DOESNT need encoding to avoid it. Thank you so much.</p>
 

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