We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

elightbo on 12/07/07


Tagged

form javascript prototype


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

vali29
drye


Handling element focus with tab


Published in: JavaScript 


This uses prototype to intercept tab focus and place it on a button (or any other element). Firefox and Safari will bypass the button when tabbing through a form. Useful for buttons after textareas.

  1. Event.observe($('body'), 'keypress', function(event){
  2. if(event.keyCode == Event.KEY_TAB) {
  3. $('sendMessage').focus();
  4. Event.stop(event);
  5. }});

Report this snippet 

You need to login to post a comment.