Reputation: 1524
I'm trying to calculate a string based on user input and show some message:
$('#myInput').keyup(function() {
if(this.value.length<=158)
$('#charCount').text('We will deduct 1 credit from your account');
else if(this.value.length>158 || this.value.length<316)
$('#charCount').text('We will deduct 2 credit from your account');
else if(this.value.length>316 || this.value.length<400)
$('#charCount').text('We will deduct 3 credit from your account');
});
The problem is the last else if
is not working... Have I missed something?
Upvotes: 0
Views: 6990
Reputation: 385098
else if(this.value.length>158 || this.value.length<316) $('#charCount').text('We will deduct 2 credit from your account'); else if(this.value.length>316 || this.value.length<400) $('#charCount').text('We will deduct 3 credit from your account');
Every number in the world is greater than 158 or less than 316, so the alternative condition will never be reached.
Upvotes: 4
Reputation: 4185
It looks like you mean &&, not ||
$('#myInput').keyup(function() {
if(this.value.length<=158)
$('#charCount').text('We will deduct 1 credit from your account');
else if(this.value.length>158 && this.value.length<=316)
$('#charCount').text('We will deduct 2 credit from your account');
else if(this.value.length>316 && this.value.length<400)
$('#charCount').text('We will deduct 3 credit from your account');
});
Upvotes: 7