Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
takinbo
/
keypress_nav.js
Created
Feb 25, 2012
Star
1
Fork
0
Star
Code
Revisions
1
Stars
1
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
Form Navigation
Raw
keypress_nav.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
// Adds the ability to navigate text boxes while pressing either n or p
$
(
'.bigbox2'
)
.
keypress
(
function
(
e
)
{
switch
(
e
.
which
)
{
case
78
:
case
110
:
// N was pressed
el
=
$
(
this
)
;
prefix
=
el
.
attr
(
'name'
)
.
replace
(
/
-.
*
$
/
,
""
)
;
pos
=
$
(
'input[name|="'
+
prefix
+
'"]'
)
.
index
(
el
)
;
if
(
pos
<
$
(
'input[name|="'
+
prefix
+
'"]'
)
.
length
)
{
$
(
'input[name|="'
+
prefix
+
'"]'
)
.
eq
(
pos
+
1
)
.
focus
(
)
.
select
(
)
;
}
return
false
;
case
80
:
case
112
:
// P was pressed
el
=
$
(
this
)
;
prefix
=
el
.
attr
(
'name'
)
.
replace
(
/
-.
*
$
/
,
""
)
;
pos
=
$
(
'input[name|="'
+
prefix
+
'"]'
)
.
index
(
el
)
;
if
(
pos
>
0
)
{
$
(
'input[name|="'
+
prefix
+
'"]'
)
.
eq
(
pos
-
1
)
.
focus
(
)
.
select
(
)
;
}
return
false
;
default
:
return
true
;
}
}
)
;
Sign up for free
to join this conversation on GitHub
. Already have an account?
Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.