jquery - Inject something in jWYSIWYG at cursor pointer? -


i want inject dropdown selected value in jwysiwyg @ cursor pointer.i want that:

<select id="shirt" name="shirt">       <option value="small">small</option>       <option value="medium">medium</option>       <option value="large">large</option> </select> <a href="#" id="btn_insert" name="btn_insert">insert</a> <textarea id="testing_txt" name="testing_txt"></textarea> 

the trick cursor position reliably. found how existing so thread. once have cursor position matter of getting before , after text, inserting new value in middle.

http://jsfiddle.net/vr99u/1/

$("#mybutton").click( function() { var pos = getcaret(document.getelementbyid('mytextarea')); var currenttext = $("#mytextarea").val(); var currenttextstart = currenttext.substr(0, pos); var currenttextend = currenttext.substr(pos, currenttext.length); var newtext = currenttextstart + $("#myselect").val() + currenttextend; $("#mytextarea").val(newtext); });   function getcaret(node) {   if (node.selectionstart) {     return node.selectionstart;   } else if (!document.selection) {     return 0;   }    var c = "\001",       sel = document.selection.createrange(),       dul = sel.duplicate(),       len = 0;    dul.movetoelementtext(node);   sel.text = c;   len = dul.text.indexof(c);   sel.movestart('character',-1);   sel.text = "";   return len; } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -