Featured post
javascript - Change Enter from submission to Tab? -
users don't fact enter key submits page. tasked preventing submission , changing enter key tab next field.
i have tried many javascript snippets found on net none have worked far. 1 has come close having effect e.preventdefault() of jquery api, stops submit, nothing have tried emulates tab behavior.
e.returnvalue = false; e.cancel = true;
page still submits above in keydown event handler. same effect return false
in keydown event handler. handler firing, tested putting breakpoint in firebug.
this needs work both ie , firefox.
don't "don't this".
1) i'm convinced shouldn't it, it's not choice mine, discussion mute.
2) answer question "should this?", not question asking.
this feels icky, use event.preventdefault
mentioned , call focus()
on next closest input:
here's simple example:
$("input").bind("keydown", function(event) { if (event.which === 13) { event.stoppropagation(); event.preventdefault(); $(this).next("input").focus(); } });
example: http://jsfiddle.net/andrewwhitaker/txg65/
update: if have elements in between inputs, using plain next()
not work. instead, use nextall()
:
$("input").bind("keydown", function(event) { if (event.which === 13) { event.stoppropagation(); event.preventdefault(); $(this).nextall("input").eq(0).focus(); } });
- Get link
- X
- Other Apps
Comments
Post a Comment