Andrejs
Andrejs

Reputation: 11911

Is it valid to use div instead of form tag?

I have a bunch of <input type="text">.Is it valid to put them in a <div> and not <form> ? I'm asking because I have <button>s there too, that need to do some functionality, and clicking on them causes jsfiddle's:

{"error": "Please use POST request"}

Adding e.preventDefault() fixes the problem, but I still wonder if replacing <form> with <div> is OK? Thanks.

Upvotes: 1

Views: 2396

Answers (1)

Quentin
Quentin

Reputation: 943250

It is valid but violates the principles of unobtrusive JavaScript, introduces accessibility issues and removes useful APIs.

Having a form:

  • allows you to have a server side fallback for when the JavaScript fails.
  • groups the form controls semantically (e.g. for the benefit of screen reader software).
  • gives you access to form.elements and similar APIs for accessing controls simply (including for such things as jQuery's serialize method).

Upvotes: 2

Related Questions