I have the following jquery and want to check if the text box is empty before the code is run:
<script type="text/javascript">
$(document).ready(function () {
if ($("#FNameTB").val().length < 0) {
$("input#FNameTB").labelify({ labelledClass: "greylabel" });
}
</script>
but its not working.
IsNullOrEmpty() function has a boolean return type and returns true if the string is either null or empty and otherwise returns false . We can use the String. IsNullOrEmpty() function on the string inside the TextBox. Text property to check whether the text inside the text box is empty or not.
If the textbox is empty then the IsEmpty function returns false. If the textbox contains only '1' then IsEmpty returns true.
When the Validate Button is clicked, a JavaScript function is called and the TextBox is referenced and its value is compared with Empty string and if the condition tests TRUE then the TextBox is considered Empty.
Length will never be less than 0.
if ( $("#FNameTB").val().length === 0 )
You can even add in a trim() to be thorough
if ( $("#FNameTB").val().trim().length === 0 )
Try
if ($("#FNameTB").val() == '')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With