JSFiddle - React, Tailwind, and code Playground
HTML
<form id="myform">
<input id="firstfield" name="firstfield" class="captureKeys" value="100" type="text" />
<input id="secondfield" name="secondfield" class="captureKeys" value="200" type="text" />
</form>
<a href="#">Dummy link for final tabindex</a>
CSS
#myform input[type="text"] {
border: 1px solid #DBDAD7;
box-shadow: 1px 1px 4px #F4F4F4 inset;
font-size: 14px;
height: 47px;
line-height: 46px;
padding: 0 10px;
margin: 0;
}
.focus {background:#e6e9f0;}
JavaScript
jQuery(document).ready(function() {
(function($) {
$.fn.keyAction = function(theKey) {
return this.each(function() {
if ($(this).hasClass("captureKeys")) {
alert("Handler for " + $(this).attr("id") + " .keyup() called with key "+ theKey + ".");
// KeyCode dependent statements go here.
}
});
};
})(jQuery);
$(".captureKeys").on("keydown", function(e) {
$("*").removeClass("focus");
$(this).addClass("focus");
});
$("body").on("keyup", "*:focus", function(e) {
if (e.which == 9) {
$(".focus.captureKeys").keyAction(e.which);
$("*").removeClass("focus");
}
else {
$(this).keyAction(e.which);
}
});
});