However, the technique to generate the option list via javascript is highly browser dependent!
According to the specs - this should be pretty simple .. and it is for everything EXCEPT IE8!
| innerHTML | IE8 method |
|---|---|
In the main form
This is the associated html - pretty standard.
<select name="UIComboBox" id="UIComboBox" > <option value="Algorithms">Algorithms</option> </select> |
window.onload = function() {
var UIComboBox = document.getElementById('UIComboBox'); // *var* required in IE8
Configure_ComboBox(UIComboBox);
}
|
Expected results
Configure_ComboBox = function(ComboBox)
{
// This is typical data
var xx = "<option value=Red>Red</option> <option value=Green>Green</option>";
ComboBox.innerHTML = xx; // Works in Chrome, fails in IE8
var yy = ComboBox.innerHTML ; // just for test
}
|
In IE8, the component contains no data!!!
IE8 is broken
var xx = "<option value=Red>Red</option> <option value=Green>Green</option>"; ComboBox.innerHTML = xx; var yy = ComboBox.innerHTML ; |
Red</option> <option value=Green>Green</option> |
However, no matter what I did, I could not get the component to display the options.
These are some of the combinations I tried.
ComboBox.innerHTML = "test"; var yy = ComboBox.innerHTML ; // yy contained "test" |
var xx = "<option value=Red>Red</option> <option value=Green>Green</option>"; var ss = ComboBox.innerHTML = xx; // ss was the same as xx var yy = ComboBox.innerHTML ; // yy was missing the first option tag |
var xx = "x<option value=Red>Red</option> <option value=Green>Green</option>"; var ss = ComboBox.innerHTML = xx; // ss was the same as xx var yy = ComboBox.innerHTML ; // yy was the same as xx, but the options did not display |
var xx = "<option value=2><option value=Red>Red</option> <option value=Green>Green</option>"; var ss = ComboBox.innerHTML = xx; // ss was the same as xx var yy = ComboBox.innerHTML ; // yy was missing the first 2 option tags |
You can check this nonsense yourself
This is what works
Configure_ComboBox_IE8 = function(ComboBox)
{
var xx = ['Red','Green']; // This is just an array
ComboBox.innerHTML = "" ; // erase the dummy contents
var option ;
for (var i = 0; i < xx.length; i++) {
option = document.createElement("option");
option.text = xx[i];
option.value = xx[i];
ComboBox.add(option, i);
}
}
|
Controlling the *values*
| Component | ComboBox.value |
|---|---|
function mcExample_setClassOptions(ComboBox)
{
var optionsClass = [ // This is an array of classes
{text:'Red', index:1},
{text:'Green', index:2}
];
ComboBox.innerHTML = ""; // clear the current (dummy) contents
var option ;
for (var i = 0; i < optionsClass.length; i++) {
option = document.createElement("option");
option.text = optionsClass[i].text;
option.value = optionsClass[i].index;
ComboBox.add(option, i);
}
}
function UIComboBox2_Changed(){
ComboBox2_Result.value = UIComboBox2.value;
}
var UIComboBox2;
var ComboBox2_Result;
window.onload = function() {
UIComboBox2 = document.getElementById('UIComboBox2');
ComboBox2_Result = document.getElementById('ComboBox2_Result');
mcExample_setClassOptions(UIComboBox2);
UIComboBox2_Changed();
}
|