Welcome Guest, Not a member yet? Register   Sign In
[Solved] Textarea indent 4 spaces jQuery & Codeigniter
#2

Hi,

I have not tested it, but is should work.
What you need to do is to find the newline and add your startTag to each line.
Because of different character for new line on Windows, Linux and Mac you need to test for all 3.
You will notice I use the \r\n (Windows linebreak) to insure it works on most systems


PHP Code:
function wrapText(elementIDopenTagcloseTag) {
 
   var textArea = $('#' elementID);
 
   var len textArea.val().length;
 
   var start textArea[0].selectionStart;
 
   var end textArea[0].selectionEnd;
 
   var selectedText textArea.val().substring(startend);
 
   var replacement openTag selectedText closeTag;

 
   replacement.replace(/\r\n|\r|\n/g,"\r\n"+openTag);

 
   textArea.val(textArea.val().substring(0start) + replacement textArea.val().substring(endlen));


Source 1 for the solution
Source 2
A good decision is based on knowledge and not on numbers. - Plato

Reply


Messages In This Thread
RE: Textarea indent 4 spaces jQuery & Codeigniter - by salain - 12-21-2016, 12:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB