0

I'm trying to know if the textbox is empty when i change of textbox, how can i do it? i tried to create a script, but i totally failed.

I'm new at jQuery.

Here my js script

$("#description").blur(function())){
if ($("#description").val() == "") alert ("Empty!");
}}

I want to know if my textarea is empty or not

<label>Description</label>
<textarea cols="55" rows="3" id="description" name="description">
</textarea>
<br><br>

What do i need to do? I dont want to call a function inside the textarea

2
  • possible duplicate of Check if textbox has empty value Commented Apr 4, 2014 at 13:39
  • do spaces count as empty??? Commented Apr 4, 2014 at 13:42

4 Answers 4

1

Wrap it in dom ready

$(document).ready(function () {
    $("#description").blur(function () {
        if ($("#description").val() == "") alert("Empty!");
    });
});

aLso your syntax has some mistakes

Sign up to request clarification or add additional context in comments.

Comments

0
$("#description").blur(function(){
if ($("#description").val() == ""){ alert ("Empty!")};
});

Comments

0

Use change

$("#description").on('change',function(){
  if(this.value == "") alert("Empty");
});

Comments

0
$(document).ready(function () {
    if ($('#element').is(':empty')){
       //do something
     }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.