Actually,I want to implent a feature which is not in ipad .If we closely observe and use the ipad we can't just place the cursor in the textfield as simply.We need to select the text and there will be magnifying image on selection of text then we need to move the cursor and can place it in the required position of the text where we need to add or edit the text.So,how to set the cursor position in the textfield programmatically so that on selected place directly the cursor is displayed.
Asked
Active
Viewed 725 times
-6
-
Does this help? [jQuery Set Cursor Position in Text Area](http://stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area) – Robin J Dec 02 '15 at 13:34
-
check this .....http://stackoverflow.com/a/841121/3143384 – Anand Singh Dec 02 '15 at 13:35
-
1Welcome to StackOverflow. Some friendly advice: it's a bad idea to change the question so drastically after it's been downvoted so many times and flagged as a duplicate. You'd be better off closing this question (since it's going to get closed anyway), and asking a whole new question, being as clear as possible, and providing examples of what you have tried. See http://stackoverflow.com/help/how-to-ask for more guidelines for asking questions here. – Howard Renollet Dec 02 '15 at 14:09
1 Answers
1
Try setSelectionRange
method on input
elements:
var inputs = document.querySelectorAll('input');
inputs[3].addEventListener('click', function() {
var start = parseInt(inputs[1].value);
var end = parseInt(inputs[2].value);
inputs[0].setSelectionRange(start, end);
inputs[0].focus();
}, false);
<input type="text" value="asdfghjkl"><br>
From: <input type="number" min="0" max="9" value="2">
To: <input type="number" min="0" max="9" value="5">
<input type="button" value="Set Selection">

Leo
- 13,428
- 5
- 43
- 61