Question

I have problem with this script:

$(function() {
$('#kontaktinput').change(function(){
    var txtVal =  $('#kontaktinput').val();
    if(isDate(txtVal))
        $(this).css({'background-color' : '#07cc2c'});
    else
        $(this).css({'background-color' : '#f8c5c5'});
        alert('Podano błędną datę !');
});

When If it's true everything it's ok, my input change background color and when If it's false it's everything ok too. But when i change my input after i saw alert its ok with background but i still see alert ?? Why ? I only want to change color to green but why i see alert when If its true ? (sorry for my English)

Was it helpful?

Solution

You are missing the curly brackets, { }. When you have more than 1 statement you need to enclose it:

else
{
        $(this).css({'background-color' : '#f8c5c5'});
        alert('Podano błędną datę !');
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top