Jump to content

Help with example off jsfiddle.net


DataSpy

Recommended Posts

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!!!

Link to comment
https://forums.phpfreaks.com/topic/241513-help-with-example-off-jsfiddlenet/
Share on other sites

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();
    }
  });
});

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.