What should an HTML value attribute contain?

Asked

Viewed 4,148 times

0

In a maintainability and organization perspective what should contain a value attribute? a number representing a word:

<label><input type="radio" name="order" value="1">Masculino</label>
<label><input type="radio" name="order" value="2">Feminino</label>
<label><input type="radio" name="loja" value="1">Ricardo Eletro</label>
<label><input type="radio" name="loja" value="2">Submarino</label>
<label><input type="radio" name="loja" value="3">Casas Bahia</label>

or content ready to be entered/searched in the database for example:

<label><input type="radio" name="order" value="Masculino">Masculino</label>
<label><input type="radio" name="order" value="Feminino">Feminino</label>
<option value="MaisCaroPrimeiro">Mais caro Primeiro</option>
<label><input type="radio" name="loja" value="RicardoEletro">Ricardo Eletro</label>
<label><input type="radio" name="loja" value="Submarino">Submarino</label>
<label><input type="radio" name="loja" value="CasasBahia">Casas Bahia</label>

When and where to convert to the actual value?

  • 1

    Guy, based on opinions, ie, depends a lot on the taste of the person. I prefer the code, (1,2,3...) in the case of sex, may be used (f, m)...

  • 1

    What do you put in value is what will be sent to the server. In the case of a radio button - where the end user does not see the attribute value - the simplest is to put the data which will be easier to be handled by the server. (always remembering to validate the die before using it)

  • I edited with one more example

  • 1

    Placing a value that is within the scope of input will always be the best approach, it is much easier you identify what is a select worthwhile m or male than one with value 1. You do not need to write the "full" value, but enough so you do not generate more complexity in your code, but all this is my opinion only, good practices, etc.

  • 1

    I voted to reopen. In my opinion, this question could not be treated specifically as "based on opinions". If you are declaring that you have a "search" method that has as Feature "sort records the way you want" the highest level would be that you have readable values. The reason these values are readable, is that imagine you were going to make your method available over a web service for example, which is more readable for your business layer ? something that represents your business (ordernar_por_idade_asc) or by column names (ASC age) ?

  • @wryel I understand your explanation.

  • As they say, it all depends on the modeling of your data and what you do with it. Do not want to [Dit] the question and add information on that part?

Show 2 more comments

2 answers

3


The value is the information that will be sent to the server, can be used 1, 2, f, m, masculino, feminino, whatever. Because it is you who will receive this information and treat the use of it. In W3S I found this example using text input that should clarify a little your doubt.

But in the end when the server receives the response from the marked button it will receive the value indicated in the attribute value, plain as that.

2

In the case of "radio", value determines the response value... It can be either 1.2 / Male, Female / M, F. It depends on how you will treat it after.

Browser other questions tagged

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