I'm trying to figure out a way to automatically select an option, based on a passed variable, that matches only the value of that option.
JS Fiddle Link Demo
<label>
    <span>Font Type</span>
    <select id="options>
        <option value="one">One</option>
        <option value="two" selected>Two</option>
        <option value="three">Three</option>
    </select>
</label>
function loadSelect(userFont){
    $('#options').find('option[value='+userFont+']').attr('selected', 'selected');
}
loadSelect(three);
                Just set the value on the <select> tag:
$('#options').val(userFont);
$(function() {
  $("#options").val("three");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select id="options">
  <option value="one">One</option>
  <option value="two" selected>Two</option>
  <option value="three">Three</option>
</select>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With