M
Max Weber
Try to run the code below in a page. You will notice than when you
switch the multiple attribute of the SELECT tag, only one option is
displayed as selected although multiple options have ben created as
selected. May somebody give me an explanation ?
<input type="button" value="test" onclick="test()"/>
<select name="tagSelect" style="width:100%">
</select>
<script defer="true">
function COption (strValue, intDefault)
{
this.value = strValue;
this.isDefault = intDefault;
}
var objOptions = new Array ();
objOptions.push (new COption ("a", 0));
objOptions.push (new COption ("b", 1));
objOptions.push (new COption ("c", 0));
objOptions.push (new COption ("d", 1));
function test () {
var intOption;
var tagOPTION;
if (tagSelect.multiple == true)
{
tagSelect.multiple=false;
}
else
{
tagSelect.multiple=true;
}
while (tagSelect.options.length != 0)
tagSelect.options.remove (0);
for (intOption in objOptions)
{
tagOPTION = document.createElement ("option");
tagSelect.options.add (tagOPTION);
tagOPTION.innerText = objOptions[intOption].value;
if (objOptions[intOption].isDefault == 1)
tagOPTION.selected = true;
}
}
</script>
switch the multiple attribute of the SELECT tag, only one option is
displayed as selected although multiple options have ben created as
selected. May somebody give me an explanation ?
<input type="button" value="test" onclick="test()"/>
<select name="tagSelect" style="width:100%">
</select>
<script defer="true">
function COption (strValue, intDefault)
{
this.value = strValue;
this.isDefault = intDefault;
}
var objOptions = new Array ();
objOptions.push (new COption ("a", 0));
objOptions.push (new COption ("b", 1));
objOptions.push (new COption ("c", 0));
objOptions.push (new COption ("d", 1));
function test () {
var intOption;
var tagOPTION;
if (tagSelect.multiple == true)
{
tagSelect.multiple=false;
}
else
{
tagSelect.multiple=true;
}
while (tagSelect.options.length != 0)
tagSelect.options.remove (0);
for (intOption in objOptions)
{
tagOPTION = document.createElement ("option");
tagSelect.options.add (tagOPTION);
tagOPTION.innerText = objOptions[intOption].value;
if (objOptions[intOption].isDefault == 1)
tagOPTION.selected = true;
}
}
</script>