Reputation: 9289
Consider:
var ret = { valid: true, message: "" };
var prtime = $(".ptime").val();
var ctime = $(".ctime").val();
if ($(prtime).length == 0 || $(ctime).length == 0) {
ret = { valid: false, message: "" };
}
$(prtime).length
When I run this, I get 0, even when I fill some words in prtime. And when I do $(".ptime").val()
.length then it shows me the length.
What have I done wrong with that code?
Upvotes: 0
Views: 49
Reputation: 66389
prtime
is a plain string. Don't wrap it as a jQuery object.
To get the amount of characters in the string, have:
var myLength = prtime.length;
Upvotes: 1
Reputation: 17485
//Use this way
var ret = { valid: true, message: "" };
var prtime = $(".ptime");
var ctime = $(".ctime");
if ($(prtime).length == 0 || $(ctime).length == 0) {
ret = { valid: false, message: "" };
}
Upvotes: 0