11
$('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?

Drew
  • 3,194
  • 8
  • 40
  • 62

3 Answers3

9

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();
});
Russell Steen
  • 6,494
  • 6
  • 38
  • 56
1

You want the focus event.

  $('a#next').focus(function() {
      $('#formcont').fadeIn('slow');
  });
Dead account
  • 19,587
  • 13
  • 52
  • 82
0

input#tags is redundant and wasteful.

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

    $('#formcont').fadeIn('slow');
    $('#next').hide('slow');
    $(this).focus();
});
tekknolagi
  • 10,663
  • 24
  • 75
  • 119
A Rad
  • 27
  • 1
  • unless you're using jquery specific selectors (eg. :not()) then saying "input" is wasteful is overkill. The programming cost of the css selector is negligible and is just looking for something to change to put a seperate answer. – Adam Botley Jan 24 '14 at 11:46