Should I use form or div?

0

In case of being sent with ajax I believe that it is recommended to use the form tag, but what if I just do something with javascript, ie only on the client side, for example change the background color of the application, or generate some random number, and is it correct to use form only to group a set of labels and inputs?

    
asked by anonymous 09.09.2017 / 22:35

2 answers

1

Tags form , intention calls HTTP , there is no sense to use them for other purposes, in requests ajax it is interesting to use them in a Progressive Enhancement MDN

In other words, if the browser does not support javascript the request will be completed in the same way, but only for forms.

  

Tag form MDN

represents a section of a document that contains interactive controls that allow the user to submit information to a particular web server.

  

Tag form w3schools

The element MAY contain one or more of the following form elements:

<input>
<textarea>
<buttom>
<select>
<option>
<optgroup>
<fieldset>
<label>

In no reference input elements are necessarily related to a form tag, just the opposite, and there are no articles in which this is considered good practice.

    
09.09.2017 / 22:58
0

In my opinion, form should be used whenever you want to use input tags in the code, at least to leave the clear code for other possible programmers.

I see it as a story that you write without a title, it will work, but it will not be 100% semantic .

Example, if you check the source code of most sites, you will see that when you have a button within a form, it usually looks like this:

<input type='button'> ou <input type='submit'>

But when used outside of a form, it is most often used like this:

<button id='x'>Ok</button> 

or even stylized links like buttons

<a href='...' class='btn btn-primary'>Ok</a>
    
10.09.2017 / 00:17