KeithMcElroy
asked on
javascript: add enter key = tab after initial load of form
Using jquery and/or javascript, how can I make the enter key same as tab, but have that happen after a button is clicked on the form, in other words not onload of the form?
The following which I found via good search works if embedded in the body tag, but that does not work for me since I need the feature to occur post-load as mentioned above.
"if(event.keyCode==13) {event.keyCode=9; return event.keyCode })"
The following which I found via good search works if embedded in the body tag, but that does not work for me since I need the feature to occur post-load as mentioned above.
"if(event.keyCode==13) {event.keyCode=9; return event.keyCode })"
ASKER
I tried this at the event where I want the 'enter to tab' feature to work
var body = $('body')
body.addEventListener("onk eydown", "if(event.keyCode==13) {event.keyCode=9; return event.keyCode }", false)
It does not work, however, maybe it is close?
var body = $('body')
body.addEventListener("onk
It does not work, however, maybe it is close?
ASKER
Yes, on set focus on next input
Are you using jQuery or just plain javascript?
ASKER
jquery, tried this (no success) but seems close
$("input").live('keyup',fu nction () {
$(this).next(".input").foc us();
});
$("input").live('keyup',fu
$(this).next(".input").foc
});
ASKER
corrected the class . still no work
$("input").live('keyup',fu nction () {
$(this).next("input").focu s();
});
$("input").live('keyup',fu
$(this).next("input").focu
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for the code, it is not working yet, but may be something about my form. I understand the steps so I bet I shall be able to make it work.
Will stand by for any further comments, otherwise shall reward points.
Will stand by for any further comments, otherwise shall reward points.
Post your code, it may need tweaking a tiny bit
ASKER
I think I see where I need help, this is an internal web form, dynamic and I've never been able to figure out how to get a working sample outside the internal network,
However, the code you did, as is, is working except in rows where I have disabled text boxes and check boxes. So, I think, if I can remove disabled inputs and check boxes from the forward cursor, it is good. I will pursue, but if you know off top of your head, how to do that would be be great. This is a big help. Thank you! Again will reward points, but want to allow for any further from you.
However, the code you did, as is, is working except in rows where I have disabled text boxes and check boxes. So, I think, if I can remove disabled inputs and check boxes from the forward cursor, it is good. I will pursue, but if you know off top of your head, how to do that would be be great. This is a big help. Thank you! Again will reward points, but want to allow for any further from you.
ASKER
the following did the trick:
$("input").keypress(functi on(e) {
if(e.which == 13) {
var index = $('input[type=text]:enable d').index( this) + 1;
var total_els = $('body').find('input[type =text]:ena bled').len gth;
if(total_els == index){index=0}
$('input[type=text]:enable d:eq('+ind ex+')').fo cus();
}
});
$("input").keypress(functi
if(e.which == 13) {
var index = $('input[type=text]:enable
var total_els = $('body').find('input[type
if(total_els == index){index=0}
$('input[type=text]:enable
}
});
ASKER
Awesome, thank you!
So you want to skip disabled elements?
Are you wanting to capture the enter key so you can set focus on the next input?