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

4 Answers4

1

Wrap it in dom ready

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

aLso your syntax has some mistakes

Anoop Joshi P
  • 25,373
  • 8
  • 32
  • 53
0

Use change

$("#description").on('change',function(){
  if(this.value == "") alert("Empty");
});
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
0
$("#description").blur(function(){
if ($("#description").val() == ""){ alert ("Empty!")};
});
RGS
  • 5,131
  • 6
  • 37
  • 65
0
$(document).ready(function () {
    if ($('#element').is(':empty')){
       //do something
     }
});
Bertotz
  • 38
  • 7