Preventing an input from losing focus?
Basically I want to prevent a user from moving to another field if the current one is invalid (non-numeric).
I've tried a few things that I though would do the job, I've also tried using the change event with the last line (resetting the focus to the current element) but no dice.
Can anyone give me a hand?
- jQuery('.setupprice, .monthlyprice, .quantity','#config_dialog').live('focusout',function(e)
{
var val = parseFloat(jQuery(this).val());
if(isNaN(val))
{
jQuery(this).css('background-color','red').css('color','white');
// My attempts to do this so far
- e.stopPropagation();
- e.stopImmediatePropagation();
e.preventDefault();
return false;
jQuery(this).focus();
}
else
{
jQuery(this).val(val.toFixed(2)).css('background-color','').css('color','');
}
});