Click here to Skip to main content
15,914,394 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

I am using following code to check whether textarea is empty or not:
PHP
$(function () {
        $("#btnSave").click(function () {

var txtaAddress = $("#txtaAddress");
            if ( $(txtaAddress.val()).length <1) {
                alert('Enter address');
                txtaAddress.focus();
                return false;
            }
 }); 
	});

but its not working I have also tried:
PHP
var txtaAddress = $("#txtaAddress");
            if (txtaAddress.val()= "" || txtaAddress.val()= null) {
                alert('Enter address');
                txtaAddress.focus();
                return false;
            }

but its also not working.
Please help me to get rid of this problem.

Thank u all!!
Posted
Updated 19-Sep-15 22:11pm
v2

Try
C#
if (!$("#myTextArea").val()) {
    // textarea is empty
}


Alternately, try
C#
if (!$.trim($("#myTextArea").val())) {
    // textarea is empty or contains only white-space
}
 
Share this answer
 
Try
C#
if (!$("#txtaAddress").val()) {
    // textarea is empty
}


Alternately, try
C#
if (!$.trim($("#txtaAddress").val())) {
    // textarea is empty or contains only white-space
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900