I have an <input type="number"
which can store maximum two digits. This is achieved by using event.preventDefault();
.
function allowMaxNumbers(element, event, maxLength){
if(element.value.length==maxLength&& event.keyCode!=8 && event.keyCode!=46 && event.keyCode!=9){
if (event.preventDefault){
event.preventDefault();
}
return false;
}
}
If user selects the input and types in another number, the new number should be inputted replacing the old input. Is there a way in javascript/jQuery to find if some text is selected in the input?
I followed the question How to know if the text in a textbox is selected? and tried input.selectionStart
and input.selectionEnd
but that is not working for input type="number"