Henry wrote:
Hi all,
I would like to use a control on a WebForm that acts like an editable
DropDownList control. The user should be able to select a value from
the list of choices, or type in a new value if no predefined choice is
applicable.
It doesn't appear to me that a DropDownList control is editable.
How would you suggest I accomplish what I want to do?
Thanks in advance for your help.
I have no idea what you mean by WebForm or DropDownList.
If that are some existing packages, please mention that.
If you want to edit the contents of a SELECT-element, that is easy.
Consider the following formelement:
<FORM name="myForm" Mathos="POST">
<SELECT name="myExample">
<OPTION value="John">John
<OPTION value="Joe">Joe
<OPTION value="Berta">Berta
</SELECT>
</FORM>
From javascript
:
var theSelectRef = document.forms["myForm"].myExample;
var nrOfOptions = theSelectRef.options.length;
// get the first option:
var firstOption = theSelectRef[0];
// get its value:
var firstOptionValue = theSelectRef[0].value;
// remove the second option (joe)
theSelectRef.options[1] = null;
// add a new option (not added yet to SELECT):
// the third and fourth argument men: defaultSelected and Selected
var newOption = new Option("text","value",false,false);
// add it to the end:
theSelectRef[theSelectRef.options.length] = newOption;
Hope that gets you going.
Regards,
Erwin Moller