Reputation: 159
I am doing some validation and can't get my if
statement to work. I want to validate fields with a data type and the required attribute. Or if a field is not null?
My if statement:
if (typeof $(this).attr("data-type") != "undefined"
&& typeof $(this).prop("required") != "undefined"
|| typeof $(this).prop("required") === true
|| $(this).val() != "") {
// Doing stuff
}
The HTML input:
<input type="text" name="Consignee" id="text" data-type="text"
placeholder="Consignee" required>
Upvotes: 0
Views: 97
Reputation: 2449
There is no require typeof. try this query ...
if ($(this).attr("data-type") != "" && $(this).prop("required") != false && $(this).val()!="") {}
Upvotes: 1