tags:

views:

33

answers:

3

To improve navigation on one of the pages I am tyring to set a focus on a next available(enabled) button when leaving last data entry field.

$('input[type=text], select, textarea').filter(':last').blur(function()
    {

        $('input[type=submit][type=button]:enabled:first').focus();

    });

For some reason it only works when last data entry field is textbox. Something is wrong in the handler.

A: 

$('input').filter(':last').blur(function() {

    $('input:enabled:first').focus(); 

}); 

doesn't do the trick?

iivel
Thanks for reply. No, it won't because buttons are also 'input' elements.
Victor
So you want focus on the next input type that isn't a button? I misread the question (seemed like you wanted focus on the next button from a button).'input[type=text][type=select][type=textarea]' seems that it should work though (and so does your current handler)
iivel
I want to focus on next input type that IS a button, but with this snippet it seems it can focus on next textbox, or whatever is first
Victor
Bah, I can't figure out how to put code in a comment, reposted as a new answer.
iivel
A: 

Assign the buttons a CSS class and try $('.ButtonClass:enabled:first').focus();

Daniel Coffman
A: 
$(document).ready(function() {

$(':text,textarea,select').filter(':last').blur(function() 
    { 
        $(':button,submit:enabled:first').focus(); 
    }); 
});

<body>
  <textarea rows="3" /></textarea>
  <select>
    <option>1</option>
    <option>2</option>
  </select>  
  <input type="text" />
  <input type="button" value="Something" />
</body>

Did the trick ... pretty much identical, so I don't know what's not working for you.

iivel
Yes, it does, something else was wrong.
Victor