tags:

views:

30

answers:

1

Can someone who is a master at JS tell me what's wrong with this?

if ( $.trim($("#add-box-text").val()).length < 2 && $.trim($("#add-box-text").val()) != "Click here to add an item" ) {
    // If it's LT than 1 Character, don't submit
    $("#add-box-text").effect('highlight', {color: '#BDC1C7'}, 500);

    // Refocus
    $("#add-box-text").focus();
}
+1  A: 

For one thing, if it's less than 2 characters, it's never going to equal that string.

EDIT: Modified to reflect your comments. You want to check that it's >= and not equal to that string.

var trimmed = $.trim($("#add-box-text").val());
if ( trimmed.length >= 2 && trimmed != "Click here to add an item" ) {
    $("#add-box-text").effect('highlight', {color: '#BDC1C7'}, 500);

    // Refocus
    $("#add-box-text").focus();
}
Matthew Flaschen
I don't think that's it... I don't want avalue that's under 2 characters.. I also don't want the default value: "Click here to add an item"which is why it had the AND above ideas?
AnApprentice
@nobosh - See my comment. It is redundant. If you dont want a value under two characters, you need to do `> 2` and not `< 2`
webdestroya