new Option(text, value, defaultSelected, selected); Update: Since you want to reuse this code, here's the function for it: I don't recommend doing DOM manipulations inside a loop -- that can get expensive in large datasets. It may be that the documentation is missing this information. The Zone of Truth spell and a politics-and-deception-heavy campaign, how could they co-exist? The two negative two will be equal to 2. Instead, I would do something like this: You can read more about DocumentFragment on MDN, but here's the gist of it: It is used as a light-weight version of Document to store a segment of I don't recommend doing DOM manipulations inside a loop -- that can get expensive in large datasets. Instead, I would do something like this: var e I suspect there is a simpler way to find if a select has a certain option, but don't know what. Can you give me some pointers? the actual DOM's structure, changes made to the fragment don't affect In the end i solved my problem with data property of select2. The sum of the series is asked of us. And, finally (after quite a delay), an approach extending the prototype of the HTMLSelectElement in order to chain the populate() function, as a method, to the DOM node: The most concise and intuitive way would be: You can also differentiate the name and the value or add items at the start of the list with additional parameters to the used functions:HTMLSelectElement.add(item[, before]);new Option(text, value, defaultSelected, selected); Update: Since you want to reuse this code, heres the function for it: I dont recommend doing DOM manipulations inside a loop that can get expensive in large datasets. and unnecessarily verbose, as you said. Because jQuery doesn't throw errors when it doesn't have a set of elements, you can use this to your advantage inside an if statement. Select a character, input your real name, then click to submit and pull the lever. Scripting was recently updated to include the ability to add options. The list of selected options is an HTMLCollection object with one entry per currently selected option. Browse other questions tagged, Start here for a quick overview of the site, Detailed answers to any questions you might have, Discuss the workings and policies of this site, Learn more about Stack Overflow the company. Couple this with jQuery's chaining and you can do something like: Updated fiddle: http://jsfiddle.net/SPvrA/7/. 1. var selectElement = document.getElementById ('ageselect'); for (var age = 12; age <= 100; age++) { selectElement.add (new Option (age, age)); } Your age: element that it is attached to. Which CSS property defines the space between the element border and its content? Making statements based on opinion; back them up with references or personal experience. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. Calling .val() four times in one line is a bit ugly, I know, but you can't argue with results. what's the difference between "the killing machine" and "the machine that's killing". How to pass duration to lilypond function. For comparison, creating new fields is only available in Scripting app (not automation scripts). How can we cool a computer connected on top of or within a human brain? From the options option A is the required option. The read-only HTMLSelectElement property selectedOptions contains a list of the