How to create relationships between different data to perform an action?

Asked

Viewed 26 times

1

This statement returns me the state acronym: SC

$("#billing\\:city").val(dados.uf);

I have a select so I can’t change:

<select id="billing:region_id" name="billing[region_id]">
   <option value="">Por favor, selecione o estado</option>
   <option value="485">Acre</option>
   <option value="486">Alagoas</option>
   <option value="487">Amapá</option>
   ...
   <option value="507">Santa Catarina</option>
</select>

How could I create a relationship between the acronym and the state code to select the state of the acronym?

Like

1 answer

2


I don’t know if I got it right, but you can create attributes inside an html tag.

What I mean is this:

<select id="billing:region_id" name="billing[region_id]">
   <option value="" data-sigla="">Por favor, selecione o estado</option>
   <option value="485" data-sigla="AC">Acre</option>
   <option value="486" data-sigla="AL">Alagoas</option>
   <option value="487" data-sigla="AP">Amapá</option>
   ...
   <option value="507" data-sigla="SC">Santa Catarina</option>
</select>
  • 1

    This answer is correct, but a curiosity that I think is cool that users are aware and even I have suggested as editing, is always use the prefix 'data-' for attributes invented by the user in the html tag. Although it works without this prefix, there is this standard for private user data, and the browser does not even try to interpret when we have this prefix set. Source: http://www.w3schools.com/tags/att_global_data.asp

Browser other questions tagged

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