I have a select in HTML, which is dynamically generated.
When the page loads, I want to make the select box have a variable default option on page load, without having to change the order of the select list.
I cannot make this work by setting the value
attribute when I dynamically generate the page. It is always the top value that is visible, regardless of the value
property.
I would also like to be able to change this via jQuery after the document has been loaded.
Is this possible?
<select class="form-control input-lg" tabindex=1 id="instrument-select"
name="instrument" value="<?php echo $instrument->slug; ?>">
<?php foreach ($instrument_list as $instrument): ?>
<option value="<?php echo $instrument['slug']; ?>">
<?php echo $instrument["name"]; ?>
</option>
<?php endforeach; ?>
</select>