0

When a user hits <ENTER> after filling in the first text input field of a multi-part HTML form, how can one make it tab to the next input field rather than immediately executing the php script?

<FORM METHOD=POST ACTION="commentw.php">
Name: <input type="text" name="name" size="60"  maxlength="40">
<textarea name="comment" wrap="physical" rows="10" cols="80"></textarea>
<INPUT TYPE=SUBMIT VALUE ="Submit">
</FORM>

I have looked everywhere for a hint with no success.

Thanks in advance!

  • 1
    I am not sure why you would want to override the default behaviour here. The tab key lets you move to other inputs. Use the tabindex attribute to choose the order in which focus is given when pressing tab. `
    ` and `` are both deprecated and you are using a mix of html and xhtml.
    – Jared Feb 13 '12 at 18:20
  • This is your starting place: http://stackoverflow.com/questions/585396/how-to-prevent-enter-keypress-to-submit-a-web-form and just add in moving to the next input. – Avitus Feb 13 '12 at 18:20
  • Because too many users haven't the sense to tab to the next field, but hit ENTER after typing their name, which starts the form handler script. I want the script to ONLY run when the submit button is clicked. – user1207412 Feb 13 '12 at 20:28

1 Answers1

1

I feel that the user should still press Tab to navigate around a form. This practice is popular convention, and I think users may get confused it you resort to Enter instead.

Of course, if you really wanted to do so, you must

1) Prevent the event of form submission from bubbling up the DOM (by using jQuery event.preventDefault() function for instance.
2) Set up an event handler for pressing Tab.
3) Write a function to move around the form when this event handler is evoked.

However, I wouldn't normally do this. I feel that it is counter-intuitive in terms of interface design to press enter and have a form refuse to submit.

dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206