select a value of a select


I am trying to select the value of this selector, to edit the initial value and replace it with a new one assigned by a user. but I can not give the solution. Can you give me a suggestion please ??.

Thank you very much

<select name="principalIngredient" id="principalIngredient">
    <% principalIngredient.forEach((ingredient) => { %>
      <option type="text" value="<%= ingredient %>" class="form-control"><%= ingredient %></option>
    <%  }) %>
asked by Luisa Fernanda 21.09.2017 в 21:45

1 answer


Well at first I think you do not need the attribute type="text" in option since it can take any value.

You could also use JS for this case

<select name="principalIngredient" id="principalIngredient" onchange="setValue(this)">
<option value="<%= ingredient %>" class="form-control"><%= ingredient %></option>

<script type="text/javascript">
  function setValue(rece){
     var prcc = rece.value;

so you get the value you need in the js method and you can do what you need with it.

answered by 21.09.2017 / 22:00