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.
Asked
Active
Viewed 47 times
0

sani
- 15
- 4
-
where is your code ??? – Sumanta736 Mar 02 '16 at 08:56
-
Here is the code https://plnkr.co/edit/NBgZtdq0Qy7YBvaM9SLG?p=preview – sani Mar 02 '16 at 09:12
1 Answers
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: