Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
How to set an option selected if the item of an array is equal to the value of the option?

I have a select list (let's name it fraction select list) like this which appends by jQuery:

$("#optionPanel").append('<div class="form-group col-md-3"><select id="fraction" class="form-control" width="100%" id="navigationMethod"><option value="0.0" selected="">Nothing</option><option value="1.0">100%</option><option value="0.9">90%</option><option value="0.8333333">83.33333%</option><</select>');

when I click on a button, I can get the value of the select list and set it inside a variable.

var selectedOption : '';

$('#submitBtn').on('click',function(){
   selectedOption = $('#fraction').val()
});

Now I have an edit button too, I want to do something when I clicked on the edit button, the `fraction selectlist's value be as the same as the selectedOption's variable's value and the option be selected.

As I said, my selectlist is being generated by jQuery, it's not a simple HTML selectlist so we can use selected attribute easily.

I would appreciate it if you help me with that.

Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can pass the selectedOption on click of edit button which will change the selected value in select.

$("#optionPanel").append('<div class="form-group col-md-3"><select id="fraction" class="form-control" width="100%" id="navigationMethod"><option value="0.0" selected="">Nothing</option><option value="1.0">100%</option><option value="0.9">90%</option><option value="0.8333333">83.33333%</option><</select>');

let selectedOption = "0.9";

$('#editBtn').on('click', function () {
  $("#optionPanel select").val(selectedOption);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id='optionPanel'></div>
<button id="editBtn"> EDIT</button>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda