Insert word and no value in my database

0

I have an update form, where is a select and you can choose the area if you want to edit, when choosing any, in my database update the value of the option.

These data are filled through js, they are not static inside the html.

In an html table where the data is displayed, when updating the area, it shows me the value 2, which corresponds to Auxitrol. And where I need to show the word.

I am filling the data in the table by means of a function in js. And this is where I say it will show the area.

var CellArea = document.createElement('td');
CellArea.innerHTML = activos[i].name_area;
    
asked by Pato 26.11.2018 в 22:54
source

1 answer

0

To get the text of a particular option from a < select > you can use the following code:

var valor = "2";
var options_select = document.getElementById("outAreaEdit").options;
var array = [...options_select];

var encontrado = array.find(function(elemento) {
  return elemento.value == valor;
});

console.log("El texto es " + encontrado.text);

var CellArea = document.createElement('td');
CellArea.innerHTML = encontrado.text;
<select class='form-control' id='outAreaEdit'>

  <option value='4'>Norwich</option>
  <option value='3'>Todas las Areas</option>
  <option value='2'>Auxitrol</option>
  <option value='1'>Weston</option>

</select>
    
answered by 27.11.2018 в 12:14