qqruza
qqruza

Reputation: 1417

need to check textarea if nothing typed or defaultValue

I am trying to check inside textarea if there is nothing typed or default value exist with this code:

 if ($("#ipt-content").val() == '' && $("#ipt-content").val() == defaultValue) {
        $("#ipt-content").addClass("ipt-error");
        valid = false;
        emptyFields = true;
    } else {
        $("#ipt-content").removeClass("ipt-error");
    }

Unfortunately the code doesn't work. Can you please help me guys?

Upvotes: 1

Views: 64

Answers (2)

Butani Vijay
Butani Vijay

Reputation: 4239

If your default value is line and condition required || ( logical or ) then change your code as below :

 var defaultValue="line";
  if ($("#ipt-content").val() == '' || $("#ipt-content").val() == defaultValue) {
        $("#ipt-content").addClass("ipt-error");
        valid = false;
        emptyFields = true;
    } else {
        $("#ipt-content").removeClass("ipt-error");
 }

Upvotes: 2

Blender
Blender

Reputation: 298106

&& is the logical AND. You want ||, the logical OR.

Upvotes: 6

Related Questions