Alex Rivera | Logout

Multiple submit buttons in an HTML form

Asked 2008-08-01T13:01:17.303
294

Let's say you create a wizard in an HTML form. One button goes back, and one goes forward. Since the back button appears first in the markup when you press Enter, it will use that button to submit the form.

Example:

<form>
  <!-- Put your cursor in this field and press Enter -->
  <input type="text" name="field1" />

  <!-- This is the button that will submit -->
  <input type="submit" name="prev" value="Previous Page" />

  <!-- But this is the button that I WANT to submit -->
  <input type="submit" name="next" value="Next Page" />
</form>

I would like to get to decide which button is used to submit the form when a user presses Enter. That way, when you press Enter the wizard will move to the next page, not the previous. Do you have to use tabindex to do this?

Edit
Report

1 Answer

17

You can do it with CSS.

Put the buttons in the markup with the Next button first, then the Prev button afterwards.

Then use CSS to position them to appear the way you want.

answered 2008-09-16T12:16:05.913

Your Answer