tsunami

log in
history

adding options via javascript

Luke Breuer

To add options to a select element, use
select.options.add(new Option('innerText', 'value'))

While using document.createElement('option') works, IE has issues if you attempt to
  1. select.appendChild(...) such a newly created option
  2. attempt to set select.value = {new option's value}
via a button — it tends to totally ignore the new assignment unless the new option is the only one in the select

The above works in IE 6.0 and Firefox 1.5.