WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to insert data into post area? (4 posts)

  1. Canha
    Member
    Posted 3 years ago #

    Hey guys, I have a question.

    I'm creating a plugin that shows a custom box in a custom post type area. When the user inserts data into an input inside this custom box, the plugin uses this value to return another one.

    How can I automatically copy this input into the post area? (Where the post is written). I've considered just telling the user to CTRL+C, CTRL+V in the post area. But there has to be another way. I thought of Javascript, but I want to know if there is any other way to do this.

    Thanks!

  2. juliovedovatto
    Member
    Posted 3 years ago #

    Try this (javascript):

    window.send_to_editor('VALUE THAT U WANT');
    window.location.hash = 'postdivrich';

    I respond to you here, because in twitter you never see what I send to you LOL

  3. Canha
    Member
    Posted 3 years ago #

    Thanks! Sorry, didn't see you reply on Twitter (keep getting lots of those).

    I ended up using javascript in a different way, as I couldn't find a non-JS solution:
    document.getElementById("content").value = "<?php echo $myVar; ?>";

    as #content is the ID for the textarea.

    I'm leaving this here for anyone who might have this trouble:
    It's easier to use Javascript (or jQuery) to insert data into the post textarea. If you must insert the data without cleaning up the textarea, do the following:

    var whatIsAlreadyThere = document.getElementById("content").value;
    var whatYouWantToAdd = "Whatever you want to add";
    document.getElementById("content").value = whatIsAlreadyThere + whatYouWantToAdd

    You may want to add some kind of space in the second var.

  4. Leo Blanchette
    Member
    Posted 3 years ago #

    juliovedovatto,

    two months later...had to express thanks! You solved my problem in two lines of code. Thanks a lot!!!!!!!

    Original thread...

    http://wordpress.org/support/topic/click-image-insert-to-writing-area-how-is-this-done?replies=4#post-2027606

Topic Closed

This topic has been closed to new replies.

About this Topic