I have some jQuery code where I want to find user's input length but every time instead of giving user's input length, it is returning max length defined on the text box. How can I achieve this?
What I want to achieve using jQuery is this:
I want whenever user type 0
, I want to convert it to 000
, but when user type 70
, it is also converting it to 000
, which I want to keep as it is. So I want this to fire only when user input length is less then 1. Input user box has a max length defined in HTML which is 3.
Your input is really appreciated.
Here is my jQuery code:
$(document).ready(function(){
$("input:[id*=txtFairIsaacScore]").keydown(function(event){
if($("input:[id*=chkFairIsaacScoreEdited]").is(":checked")){
//$("input:[id*=txtFairIsaacScore]").unmask();
var cp_value = $("input:id*=txtFairIsaacScore]").val().length;
alert(cp_value);
if(cp_value <= 1){
if ((event.keyCode == 48) || (event.keyCode == 96)){
$("input:[id*=txtFairIsaacScore]").val("000");
}
}
}
});
});