Answer the question
In order to leave comments, you need to log in
How to check if TAB is pressed in textarea?
I have a textarea and two buttons, pressing the TAB button selects the next object in , rather than generating (4) spaces in the textarea. Can you tell me how to do it manually? <div>Объекты внутри этого "дива" выделяются</div>
Answer the question
In order to leave comments, you need to log in
I figured it out myself:
document.getElementById('OBJECT ID').addEventListener('keydown', function(clickevent) {
if (clickevent.key=='Tab') {
var begin = this.selectionStart;
var e = this.selectionEnd;
this.value = this.value.substring(0, begin)+"\t"+this.value.substring(e);
this.selectionStart = this.selectionEnd = begin+1;
clickevent.preventDefault();
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question