Should I use form or div?

Asked

Viewed 369 times

0

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

  • You can use the DIV tb to group a set of Labels and inputs if you don’t need the form. <div id="minhaDiv">labels e inputs aqui</div>.

2 answers

1

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

that is, 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 given web server.

Tag form w3schools

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

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

In no reference input elements are required to be related to a tag form, only the contrary, and there are no articles in which this is considered good practice.

  • interesting article from mdn, need to study much more html and css

  • has some course that reensine html and css?

  • Free youtube is the way, for html, css and jquery recommend 'course in video', for javacript, nodejs, and Angularjs, search for 'Rodrigo branas'

  • If the answer helped you in any way, mark it as best in the upper left, it helps the site and other users.

0

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

I see it as a story you write without a title, it’ll work, but it doesn’t get 100% semantic.

Example, if you check the source code of most websites, you will see that when you have one button, within form, it’s usually like this:

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

but when used out of a form, it is most often used so:

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

or even stylized links like buttons

<a href='...' class='btn btn-primary'>Ok</a>
  • form derived form, say I want to make a multiple choice system in SPA, in each transition several input radios are placed, ie if I have 100 questions, I will have to open 100 tags form without at least using them as they will be submitted in angular, I don’t see maintainability in that. the tag should be open for any and all HTTP request intentions and not on account of external components

  • I didn’t get your example right. Could you mount one in your reply or pass some link? I figured both in case you use div, how much form, would use only one of them and inside would come how many inputs were necessary.

  • I edited it to be clearer, but this is a good discussion I think is worth a question

Browser other questions tagged

You are not signed in. Login or sign up in order to post.