tags:

views:

23

answers:

1

I want to insert an image in textarea with jquery. (I know that img tag could not to inserted in textarea). Im using tinymce

 <img src="image.jpg" class="po"/>
 <form>
 <input type="text" name="yassi" class="infobox"/>
 <br />
 <textarea class="me"></textarea>
 <input type="submit"   value="click"  class="submit"/>
 </form>

jquery:

<script type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "simple"
});
</script>
<script type="text/javascript" scr="config.js">
</script>

and in config.js I have:

 $(document).ready(function(){
    var sr = $('.po').attr('src');
    $('.po').click(function(){
        $('.mceContentBody').append('<img src="'+sr+'"/>');

    });});

When clicking, image couldnt insert in textarea. How can do this? Thanks in advance.

+2  A: 

You need to call the mceInsertContent command, like this:

tinyMCE.execCommand('mceInsertContent',false,'<img src="'+sr+'"/>');

If you switch to the jQuery plugin version, it'd look like this:

$('.mceContentBody').tinymce().execCommand('mceInsertContent',false,'<img src="'+sr+'"/>');
Nick Craver
@Nick Craver, Thanks alot. Its working perfect in ff but not in ie.
phpExe
@phpExe - have an example page? I use the jQuery version without issues, not sure if the plain version has any IE quirks or not
Nick Craver
@Nick Craver, Im sorry, It was about activeX that disable js. Working perfect in ie too. Thanks.
phpExe