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

(This post was last modified: 12-21-2016, 01:55 AM by wolfgang1983.)

When I click on my button "c" it should indent the selected text by four spaces. How ever it works fine for one line but if I select multiple lines it only indents the very first line I need it to indent all selected text.

Question how to indent multiple selected lines if.

Live example here

PHP Code:
$('.c').click(function() {
 
   wrapText("message""   """);
}); 


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;
 
   textArea.val(textArea.val().substring(0start) + replacement textArea.val().substring(endlen));
}

$(
'.b').click(function() {
 
   wrapText("message""**""**");
});

$(
'.i').click(function() {
 
   wrapText("message""*""*");
});

$(
'.c').click(function() {
 
   wrapText("message""   """);
}); 
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
[Solved] Textarea indent 4 spaces jQuery & Codeigniter - by wolfgang1983 - 12-20-2016, 08:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB