Forums

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
    Posts
  • #192608
    richerimage
    Participant

    Hi

    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’);

    $(‘.wrap’).prepend(cleaned);

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

    // alert(cleaned);

    });</pre>

    `

    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).

    #192627
    richerimage
    Participant

    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??

    #192631
    richerimage
    Participant

    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.