DataSpy Posted July 9, 2011 Share Posted July 9, 2011 Problem: I want to convert the enter key to a tab key, so when a user hits enter it acts like tab. Solution: I found the javascript to fix my problem but it's not work, I have very little experience with javascript Where I found the code: http://stackoverflow.com/questions/4494552/change-enter-from-submission-to-tab Demo of the code online: http://jsfiddle.net/GRtQY/19/ I know it uses Jquery and I do have that included in my script, I'm including the javascript in the head of my web page, I'm wondering if that's the problem. Right above the framework option on http://jsfiddle.net/GRtQY/19/ there's an option (I'm assuming) of how to include the script, if I use "no wrap (head)" the script won't work but if I use "onLoad" it does. On my webpage: (in between head tags) $("input").bind("keydown", function(event) { if (event.which === 13) { event.stopPropagation(); event.preventDefault(); $(this).nextAll("input").eq(0).focus(); } }); (in between body tags) <form action="#"> <input name="field-one"/> <div>asdadsa</div> <input name="field-two"/> <input type="submit" value="submit"/> </form> Any help greatly appreciated, Thanks in advance!!! Quote Link to comment https://forums.phpfreaks.com/topic/241513-help-with-example-off-jsfiddlenet/ Share on other sites More sharing options...
DataSpy Posted July 14, 2011 Author Share Posted July 14, 2011 This works $(document).ready(function() { var focusables = $(":input").not('[type="image"]').not('[type="submit"]'); focusables.keydown(function(e) { if (e.keyCode == 13) { e.preventDefault(); var current = focusables.index(this), next = focusables.eq(current + 1).length ? focusables.eq(current + 1) : focusables.eq(0); next.focus(); } }); }); Quote Link to comment https://forums.phpfreaks.com/topic/241513-help-with-example-off-jsfiddlenet/#findComment-1242548 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.