I have a simple choice, div variable and prepopulate.
Here is what I want to do:
I have a preopulate value, say:
prepop = 2;
I want to find all the options in the select element, add the attribute selected to the option with a value of 2, and write “Val two” in the test div:
<div id="test"></div> <select> <option value="1">Val one<option> <option value="2">Val two</option> </select>
Any ideas how?
Here are my thoughts:
var $options = "get all the select options"; $options.each(function(){ if (jQuery(this).val() == prepop){ jQuery('#test').html(jQuery(this).text()); } }); }
source share