1

How to make possible the use of tabulation inside the textarea? So when you press tab was put 4 spaces, and it does not go to the next item.

aphex
  • 1,147
  • 1
  • 12
  • 17

1 Answers1

0
$(document).delegate('#textbox', 'keydown', function(e) {
  var keyCode = e.keyCode || e.which;

  if (keyCode == 9) {
    e.preventDefault();
    var start = $(this).get(0).selectionStart;
    var end = $(this).get(0).selectionEnd;

    // set textarea value to: text before caret + tab + text after caret
    $(this).val($(this).val().substring(0, start)
                + "\t"
                + $(this).val().substring(end));

    // put caret at right position again
    $(this).get(0).selectionStart =
    $(this).get(0).selectionEnd = start + 1;
  }
});

See this question.

Community
  • 1
  • 1
Milo Wielondek
  • 4,164
  • 3
  • 33
  • 45