take data-value with Javascript

Asked

Viewed 279 times

0

I’m trying to get the value of the date field of a select, but I’m not getting it. Only the default value field I’m getting.

The field in select this as: "data-value2"

Using . valor2

inserir a descrição da imagem aqui

HTML:

<select
  onchange="verificaHierarquia(this)" class="form-control"
  id="hierarquia" name="hierarquia.id">
  <option value="" data-valor=0 selected>SELECIONE...</option>
  <c:forEach var="hierarquia" items="${hierarquias }">
    <option value="${hierarquia.id }"
      data-valor2="${hierarquia.nivel }">${hierarquia.descricao }</option>
  </c:forEach>
</select>
  • 1

    Could you add your HTML to the question? Remember that the site has source code support, just use the button {} of the editor.

  • @Andersoncarloswoss added

  • So what you need is to take the value of data-valor2 of the element <option>, not of <select>?

  • The ideal would be the rendered html, what you mean by data-value, you refer to data-value2 ?

  • Yes data-value is data-value2.

  • I did a test just putting " = value2;" and it worked I will test other situations.

  • @Andersoncarloswoss tried the solution of this question, and it did not work.

  • @sam has already solved it.

  • Blz! Success there.

Show 5 more comments
No answers

Browser other questions tagged

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