I am developing one ASP.NET application with VB code.I have one textbox to hold the amount, which contains default value as \"0.00\". Now the problem is while the textbox gets f
assume you have TextInput
you want to select its first character, whenever its selected
<input id="MyText" type="text" value="text" onclick="MyText_click()" />
and the script is like this:
<script>
function MyText_click() {
var input = document.getElementById("MyText");
createSelection(input, 0, 1); // first character
};
function createSelection(field, start, end) {
if (field.createTextRange) {
var selRange = field.createTextRange();
selRange.collapse(true);
selRange.moveStart('character', start);
selRange.moveEnd('character', end);
selRange.select();
field.focus();
} else if (field.setSelectionRange) {
field.focus();
field.setSelectionRange(start, end);
} else if (typeof field.selectionStart != 'undefined') {
field.selectionStart = start;
field.selectionEnd = end;
field.focus();
}
}
</script>
Create event for text focus
Now we have two properties
txt.SelectionStart = intValue
and
txt.selectionLength = length;
Use this property to resolve your stuff
you can do that programmatically using javascript
, see this: Programmatically selecting partial text in an input field