Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery to check when a someone starts typing in to a field

Tags:

jquery

$('a#next').click(function() {
    var tags = $('input[name=tags]');

    if(tags.val()==''){

    tags.addClass('hightlight');  
    return false; 
    }else{
    tags.removeClass('hightlight');
    $('#formcont').fadeIn('slow');
    $('#next').hide('slow');
        return false;
    }
});

I would like the above code to fire the fadeIn as soon as somebody starts typing into the tags input. Can somebody tell me the correct way to do this or point me in the right direction? Thanks in advance

EDIT

here is the code to do it:

$('input#tags').keypress(function() {

    $('#formcont').fadeIn('slow');
    $('#next').hide('slow');
});

The only problem I've found is that my cursor no longer shows up in the text box. What am I doing wrong?

like image 350
Drew Avatar asked Mar 25 '10 16:03

Drew


2 Answers

You want the focus event.

  $('a#next').focus(function() {
      $('#formcont').fadeIn('slow');
  });
like image 152
Dead account Avatar answered Oct 07 '22 01:10

Dead account


Sounds like the fade is moving your focus, hence the cursor no longer being there. Try this

$('input#tags').keypress(function() {

    $('#formcont').fadeIn('slow');
    $('#next').hide('slow');
    $(this).focus();
});
like image 23
Russell Steen Avatar answered Oct 07 '22 01:10

Russell Steen