I have a text input which I validate its value when event "blur" triggers . when the value is not valid , I change the input background color , and when I resolved the error I want the original color and style of the input to be set again to it . but what's happening that I'm losing the original style after resolving the error or getting the error , in general that's happening when changing input's style . I tried to look for the original style to set it again but I couldn't find it in jqueryui styles . need your help :
HTML Code :
<input type='text' name='val1' id='val1'/>
jQuery Code :
function is_numeric(value)
{
var pattern= new RegExp(/^[0-9]+$/);
return pattern.test(value);
}
$(document).ready(function ()
{
$('#val1').blur(function()
{
if(!is_numeric($('#val1').val()))
{
$('#val1').css('background-color','#E65050');
}
else
{
$('#va1').css('background-color','white '); /// here ??
}
});
});
please use class see the DEMO
CSS
.error {background-color:#E65050}
jQuery
function is_numeric(value)
{
var pattern= new RegExp(/^[0-9]+$/);
return pattern.test(value);
}
$(document).ready(function ()
{
$('#val1').blur(function()
{
if(!is_numeric($('#val1').val()))
{
$('#val1').addClass('error');
}
else
{
$('#va1').removeClass("error");
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With