I have this if statement that works on two different pages, however these two pages both have a field with a different name, so I have to use the OR in my If statement, But its not working. Here is my code…
if ($("#searchValue").val().length > 100 || $("#txtSearch").val().length > 100) {
}
Why I debug, it says “Uncaught type error: Cannot read property ‘length’ of undefined”.
Is this because one of the property ID’s doesn’t exist on the page or what? how do I get around this?
Thanks
valreturnsundefinedwhen the jQuery collection is empty.You can do this :
Another solution if you’re sure to have exactly one of the two fields: