abc
abc

Reputation: 215

Get list items in select tag

How do I get list items in select tag?I have tried many different ways but nothing worked. my code:

<select id ="listBox" multiple="multiple" style="width:200px; height:400px;">
    <option></option>
</select>

function onSuccess1() {
var lstBox= document.getElementById('listBox'); 

lstBox.options.length = 0;

var listEnumerator = listItems.getEnumerator();

while (listEnumerator.moveNext()) {

    var currentItem = listEnumerator.get_current();
    var listBoxItems = currentItem.get_item("Title");
    lstBox.options[lstBox.options.length] = new Option(listBoxItems, currentItem.get_item("Title"));
}

Upvotes: 0

Views: 76

Answers (1)

Tom Doodler
Tom Doodler

Reputation: 1559

Honestly I dont get your code so here is like it works in general:

function add()
{
  var select = document.getElementById ("my_select");
  var o = document.createElement("option");
  o.text = "New Option";
  select.add (o);
}
Click the button to add an option to the select list.
<br>
<select id="my_select">
</select>
<input type="submit" onclick="add();" value="Add another option" />

Upvotes: 1

Related Questions