Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //If you're drawing the data from an array within the object (in this case, an array identified by the property options on the resulting object):
- //JSON:
- {
- "optionsValues": [
- {"value": "New1", "text": "New Option 1"},
- {"value": "New2", "text": "New Option 2"},
- {"value": "New3", "text": "New Option 3"}
- ]
- }
- //JavaScript:
- $.ajax({
- url: "http://jsbin.com/apici3",
- dataType: "json",
- success: function(data) {
- var options, index, select, option;
- // Get the raw DOM object for the select box
- select = document.getElementById('theSelect');
- // Clear the old options
- select.options.length = 0;
- // Load the new options
- options = data.optionsValues; // Or whatever source information you're working with
- for (index = 0; index < options.length; ++index) {
- option = options[index];
- select.options.add(new Option(option.text, option.value));
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement