1

I have a series of input fields and I want the focus to jump to the next field whenever the text of the current field has been change. My code looks like this:

inputs.change(function(){
            $(this).nextAll('input:first').focus();
        })

jsfiddle : http://jsfiddle.net/x6aqt/1/

Problem is that the script seems to be triggering the on blur event and not the on change event which kind of defeats the purpose. Is there anyway to make work as intended?

Bruno
  • 5,772
  • 1
  • 26
  • 43
silkAdmin
  • 4,640
  • 10
  • 52
  • 83
  • The change event fires when the field loses focus, if its value has changed. What are wanting to happen? Focus to jump to the next input when the value changes at all (try the `keyup` event)? – James Allardice Jul 24 '12 at 08:02
  • are you expecting a single character or a word? – Simon Jul 24 '12 at 08:03
  • @AnkitGautam - Obviously you would need some checks around it. You could also use the `input` event, supported in modern browsers. – James Allardice Jul 24 '12 at 08:04

1 Answers1

2
$("input").keyup(function(){
          if(this.defaultValue!=$(this).val()&&$(this).val()!='')
            $(this).nextAll('input:first').focus();
        })

Working Demo

bugwheels94
  • 30,681
  • 3
  • 39
  • 60