Hi guys, having a bit of a problem validating something. To put it simply, I have a form and when you start typing into one of the fields, a load of suggestions are made (obtained from my database). Doing real time validation on what they select from these suggestions was difficult, so I done a regex instead. This is what I came up with
Code:
$("[name=selectGame]").blur(function(){
var to = $("input[name= selectGame]").val();
if(to != 0)
{
if(isValidExpression(to)){
$("#game").css({
"background-image": "url(‘/tick.png')"
});
} else {
$("#game").css({
"background-image": "url(' /cross.png')"
});
}
}
else{
$("#game").css({"background-image": "none"});
}
});
So firstly it checks thats the inputs not null, and if it is, it will display nothing in the image holder "game". If there is input, it firstly checks it against the regex. If it matches, it displays a tick, and if it doesnt, it displays a cross.
This is all done in real time. At the moment, everything works fine apart from one small thing which I was hoping to fix. I get the expected outcomes barring one situation. As soon as I select something from the suggested items which pop up, I am displayed a cross until I click into another field. So it does eventually show the correct image (a tick), but only when I click away. Is there anyway to stop any image from showing until I click away from the field? Or maybe something better than blur which I can use?
Cheers