vbWhiz
asked on
Adding OPTION Objects to a SELECT form element in IE5
I've got two fairly standard functions written (one in javascript and on in vbscript) to add options to select form elements. The problem is that in IE5 neither properly assigns the 'value' for the option. The description and the option work otherwise.
Has the 'value' simply been ignored for the option in IE5, is this a bug? can anybody provide an explaination or solution to this?
<SCRIPT language='JavaScript'>
function jvAddToList( objSelect, strText , strValue)
{
var newopt = new Option(strText);
newopt.Value = strValue;
newopt.selected = true;
objSelect.options[objSelec t.options. length] = newopt;
}
</script>
<SCRIPT LANGUAGE=VBScript>
Sub vbAddToList(objLst, strDesc, strVal)
Dim objElement
Set objElement = document.createElement("OP TION")
ObjElement.text = strDesc
ObjElement.value = strVal
objLst.add(objElement)
End Sub
</Script>
Has the 'value' simply been ignored for the option in IE5, is this a bug? can anybody provide an explaination or solution to this?
<SCRIPT language='JavaScript'>
function jvAddToList( objSelect, strText , strValue)
{
var newopt = new Option(strText);
newopt.Value = strValue;
newopt.selected = true;
objSelect.options[objSelec
}
</script>
<SCRIPT LANGUAGE=VBScript>
Sub vbAddToList(objLst, strDesc, strVal)
Dim objElement
Set objElement = document.createElement("OP
ObjElement.text = strDesc
ObjElement.value = strVal
objLst.add(objElement)
End Sub
</Script>
ASKER
I don't think you completely understand the dilemma. This is code that has been time tested and proven to work (In IE4). I just installed IE5 on my work computer here and suddenly my scripts were exhibiting strange behavior. I traced it to this problem. IE5 doesn't set the value of the option. I'll try the simpler-to-look at method but I have my doubts because these other methods currently don't work in IE5.
ASKER
Wow...
Wow...
TTom, your suggestion worked. I'm not sure why though...
Anyway go ahead and lock the question to get your well-deserved points!
Wow...
TTom, your suggestion worked. I'm not sure why though...
Anyway go ahead and lock the question to get your well-deserved points!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yeah, either somebody forgot to write the property let routine for the .value property (I can still retrieve the value, just not set it) or they decided it was no longer important to include.
Either way, including it in the function works great.
Thanks a bunch.
vbWhiz
Either way, including it in the function works great.
Thanks a bunch.
vbWhiz
Most welcome!
Tom
Tom
"An option object can be created and added to a select object's options[] array, thereby adding a new item to that select field. To add a new item to "selectName", use the general construction:
document.formName.selectNa
(NB: "'s in the above construct are MINE)
The latter two options have values of 0 = false or 1 = true.
The JS option seems to be simpler than you are making it; not sure about VBS. Don't really know why your function would not work, but...
HTH,
Tom