pordonez's avatar

jQuery : check if the textbox has text or empty

Hi guys, what I'm trying to accomplish is. when the textarea is empty it will show a specific button. but when the textarea has value it will show another button. but if they remove the value it will show the other button again.

here is my code

$('#leadnote').on('keyup keypress', function(e) {
      if($(this).val().length >0) {
        alert('not null');
      }
    });

    $('#leadnote').on('change', function() {
      if($(this).val().length = 0) {
        alert('null');
      }
    })

so far when i try to put text on the textarea it will allert not null, but when i remove the text it won't alert null.

0 likes
3 replies
zainudinnoori's avatar
Level 7

Try this.

$('#emailsignin').on('keyup keypress', function(e) {
      if($(this).val().length =>0) {
        alert('not null');
      }
    });

    $('#emailsignin').on('keyup', function() {
      if($(this).val().length == 0) {
        alert('null');
      }
    })
pordonez's avatar

@zainudinnoori it worked!. thank you!.

i have to change this

if($(this).val().length =>0) {

to this to work

if($(this).val().length >= 1) {
1 like

Please or to participate in this conversation.