Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!