0

When I'm filling the field first name and then I'm using the tab to fill the field "Firstnames", the cursor is before the last name.This is happening just on Mozilla. Here is my code.

sani
  • 15
  • 4

1 Answers1

1

I don't think the selectionStart and selectionEnd fields are actually doing anything in your code because you are setting it on the jQuery object instead of the DOM element. I think the other browsers just default to putting the cursor at the end of the field.

Instead, call get(0) or [0] to get the actual DOM element when setting the selection range.

Replace this code:

var selection = firstnamesField.val().length-1;
firstnamesField.selectionStart = selection;
firstnamesField.selectionEnd = selection;

With

var selection = firstnamesField.val().length;
firstnamesField[0].selectionStart = selection;
firstnamesField[0].selectionEnd = selection;

Similar StackOverflow post:

selectionStart-End with textareas

Community
  • 1
  • 1
lblu
  • 126
  • 5