The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Solved] Replacing Textarea Value with jQuery

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #192608


    I am trying to replace a textarea’s value with that of a var named cleaned.

    The var cleaned is the existing content of the textarea minus all elements apart from the form element and its content.

    The goal of this project to take the opt-in form embed code as provided by email providers such as Mailchimp, Aweber, etc and remove all of the surrounding html, script tags, ect so that you’re just left with <form>...</form>

    Here is a pen of what I have so far.

    (There is some dummy form text you can paste in the html section)

    $( ‘#tidy’ ).click(function() {

    var content = $(‘textarea’).val();
    var cleaned = $(content).filter(‘form’);


    // $(‘textarea’).val(cleaned);

    // alert(cleaned);



    Note: This is an update from this post (I don’t would delete it but don’y this this is an option on the forum).


    Nice! Thank you – this has worked but (as typical) throws up another problem…

    It returns it as processed html – I need to retain the &lt;form&gt;, &lt;input&gt; tags etc. I wonder how this is done??


    No, not at all this seems to work! :)

    When using an actual optin form html (as supplied by mailchimp – as opposed to our ‘light’ version) we get a result of <form>undefined</form> though.

    Need to do some more digging but this is a massive step in the right direction – thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.