troubleshooting Question

Modify Javascript Code; Press Enter Key to Tab to Next Form Field; .. make cross form generic!?

Avatar of rcbuchanan
rcbuchanan asked on
JavaScript
5 Comments1 Solution2070 ViewsLast Modified:
Can u help. I found a great solution to my 'press enter key to move to next form field' on EE -> BUT I need help to modify the javascript to make it generic for all the forms I use in my web page.

i.e. the code below works for form called 'myform'.  Can anyone help me make it work for ANY form, ... and on pages where multiple forms exist!

in other words; can the javascript be called with the NEXT field's name and the FORM name involved!?

for example; onKeyDown="onEnterKey('myform','6P');" ???

Thanks!
Richard

the borrowed code I need help with:
-----------------------------------------

<html>
<head>
<script>
function onEnterKey(formElement) {
var press;
if (window.event) {
   press = window.event.keyCode;
} else if (e) {
   press = e.which;
} else {
   return true;
}
if (press == 13) {
  document.myform[formElement].focus();
  document.myform[formElement].select();
  return false
}
return true
}
</script>
</head>

<body>
<form name="myform">
<input type="text" name="2100" size="1" value="0" priorval="0" price="5.99" onKeyDown="onEnterKey('6P');">
<input type="text" name="6P" size="1" value="0" priorval="0" price="10.99">

</form>
</body>
</html>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros