javascript - Possible to know the position of the text cursor in an input field -
if user typing in input field, know can focus on element put cursor there, there way position cursor in input? half way? thanks
try this
function getcursorlocation(currenttextbox) { var currentselection, fullrange, selectedrange, locationindex = -1; if (typeof currenttextbox.selectionstart == "number") { locationindex = currenttextbox.selectionstart; } else if (document.selection && currenttextbox.createtextrange) { currentselection = document.selection; if (currentselection) { selectedrange = currentselection.createrange(); fullrange = currenttextbox.createtextrange(); fullrange.setendpoint("endtostart", selectedrange); locationindex = fullrange.text.length; } } return locationindex; }
associate function onkeyup, onkeydown , onmouseup , onmousedown location tryit out on here
Comments
Post a Comment