On my form there are two fields days and month.
I want to do simple validation for that. Once user enter the month , i.e., 12 then only it will be alllow to go to the next field.
If user enters invalid month then it should focus again on the month field and previously entered text should be selected.
I am trying to use .focus() and .select() jQuery function but its not working
This is fiction validation just to test , it can be any number or any label.
here is the jSFiddle link.
<input type="text" id="days" /> <input type="text" id="month" />
jQuery("#days").blur(function(){
if(jQuery(this).val() == "12"){
alert("valid");
}
else {
alert("invalid");
jQuery(this).focus().select();
}
});
1 Answer