Return key behavior

I've got an ASP.NET gridview that I've modified by causing an "insert" row to appear in the middle of it.  The insert row has one text input field (and variations may have several).   This is all done in javascript.    I don't think the ASP.NET aspect matters but I thought I would describe it to be clear.

What I now need to know is how I might control the return key behavior in this situation.  I'd like the return key to do nothing if the focus is on the text fields.  Then, when the focus is on an <img> that I'm using as an "enter" key, I'd like the enter key to essentially "press the button" (or fire the associated function).

Any guidance on this would be appreciated.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

When you specify each field that you want to 'tab' between, give each field a tab index, and use the DOM to select the next field if the enter key is pressed.  If you want a field or object to be skipped when tabbing, give it a value of "-1"

<input type="textfield" name="myfiels" id="myfield" tabindex="1" onkey="return enter(document.formename.nextfieldyouwant)"

The javascript enter() function I use is:

   function enter(nextfield) {
           if(window.event && window.event.keyCode == 13) {
                   return false;
           } else {
                   return true;

I also use a no enter() function to make sure that somebody can press the <enter> key when writing in a text area without submitting the form:

function noenter() {
  return !(window.event && window.event.keyCode == 13);

<textarea name="comment" ...  onKeyPress="return noenter()" >Enter somtext in this text area..</textarea>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
codequestAuthor Commented:
Looks good.  I'll run through it in detail and get back.  Thanks!
codequestAuthor Commented:
Works good.  Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.