I am trying to change the color of an input cell to pink when a user types an incorrect key. Although I can successfully change the color, I am facing difficulty in resetting it after they click on the cell. I have attempted using .prop("disabled", false), but it doesn't seem to work as expected. Can someone guide me on what I might be missing here?
function setUnitField(a) {
$(function () {
var tbl = $(document.getElementById('21.125-mrss-cont-none-content'));
var str1 = 'Each';
var str2 = 'Dozen';
var str3 = 'Foot';
var str4 = 'Us Gallon';
tbl.find('tr').each(function () {
$(this).find("input[name$='8#if']").keypress(function (e) {
if (e.which == 13) {
if ($(this).val() == 'EA') {
$(this).val(str1);
$(this).css("background-color", "");
} else {
$(this).css("background-color", "pink");
}
if ($(this).val() == 'DZ') {
$(this).val(str2);
}
if ($(this).val() == 'Ft') {
$(this).val(str3);
}
if ($(this).val() == 'GAL') {
$(this).val(str4);
}
}
});
});
});
}
<input id="grid#21.125#1,8#if" ct="I" type="text" maxlength="3" tabindex="0" ti="0" class="lsTblEdf3 lsTblEdf3NoEllipsis" value="" autocomplete="off" autocorrect="off" name="grid#21.125#1,8#if" onfocus="cellClick('grid#21.125#1,8','true');" onkeypress="cellKeyPress('grid#21.125#1,8',event);" oninput="setCacheValue(this); setUnitField(this);">