Search code examples
javascriptjquerycursorfocustextarea

Add the letters to the end in a textarea


I want to add the newly entered key board inputs at the end of the current wordings in the textarea even the user tries to put the cursor in the middle.


Solution

  • Try this fragment of code it worked for me. jsfiddle here

      $("#InputAtLast").keyup(function(e) {
        this.selectionStart = this.selectionEnd = this.value.length;
      });
      $("#InputAtLast").focus(function(e) {
        this.selectionStart = this.selectionEnd = this.value.length;
      });
      $("#InputAtLast").click(function(e) {
        this.selectionStart = this.selectionEnd = this.value.length;
      });
    

    For more options try this link here Click here.