The enter key press should work like a Tab key press.The enter key press for TextArea and Submit Button should work as usual.Focus should skip from the next element when the next field is disabled/readonly.
thanks,
Add("onKeyDown", "ModifyEnterKeyPressAsTab();"); In the above example, any time a user has focus on the Textbox and presses a key our JavaScript function will be called. If the key press is Enter, the function will return a Tab key press which moves focus to the next control in TabIndex order.
Keycode 13 is the Enter key.
First off, this is probably not a great idea usability-wise. However, here's something that should work:
$(":input").on("keydown", function(event) {
if (event.which === 13 && !$(this).is("textarea, :button, :submit")) {
event.stopPropagation();
event.preventDefault();
$(this)
.nextAll(":input:not(:disabled, [readonly='readonly'])")
.first()
.focus();
}
});
Example: http://jsfiddle.net/NDcrk/
The piece that finds the next input may have to change, depending on your markup.
This solution work for me. Tested it on IE and FireFox.
<script type="text/javascript">
function tabE(obj, e) {
var e = (typeof event != 'undefined') ? window.event : e; // IE : Moz
if (e.keyCode == 13) {
var ele = document.forms[0].elements;
for (var i = 0; i < ele.length; i++) {
var q = (i == ele.length - 1) ? 0 : i + 1; // if last element : if any other
if (obj == ele[i]) {
ele[q].focus();
break
}
}
return false;
}
}
</script>
<form METHOD="POST">
<input name="" type="text" onkeypress="return tabE(this,event)">
<br>
<input name="" type="text" onkeypress="return tabE(this,event)">
<br>
<input name="" type="text" onkeypress="return tabE(this,event)">
<br>
<INPUT TYPE="submit" Value="Ok">
</form>
I found it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With