Hi there,
I have a question about how I can shorten a Jquery if statement. In my form I have several fields that I check if they are filled. I know there are several plugins to do that for me, but I wan't to learn it by myself (with some help of others ;-))
I got this check
//---- First define hasError
var hasError = false;
//---- Get the value from the inputfield
var firstname = $('#firstname').val();
//---- Do the check
if(firstname == ''){
$("#error_firstname").show();
hasError = true;
}else{
$("#error_firstname").hide();
}
I thought I could write it like this:
(firstname == '') ? $(".firstname").show(): $(".firstname").hide();
And this works, but I can't put the hasError=true in it, so I can't ask this in the end
if(hasError != false) {
//---- if error, don't refresh page and show errors
return false;
}else{
//---- Save values to DB and show succes message
}
Anybody got an idea?
Tnx in advance
Grtzz
Wim