editable drop-down list

H

Henry

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.
 
E

Erwin Moller

Henry said:
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
 
H

Henry

Thanks, Erwin.

I wish to apologize for my poor explanation.
Actually, I wish to have an editable HTML select control.
That means if the user cannot find the intended value from the select
control, then he can type the value himself.
In other words, the select control can also act like a text field
sometimes.
 
E

Erwin Moller

Henry said:
Thanks, Erwin.

I wish to apologize for my poor explanation.
Actually, I wish to have an editable HTML select control.
That means if the user cannot find the intended value from the select
control, then he can type the value himself.
In other words, the select control can also act like a text field
sometimes.

Hi,

My examplecode should easily get you going.
Pay attention to the new option example.

In short:
1) Make the SELECT and populate it with options.
2) Offer a textfield (type="text") where the client can type a new value
3) add a button "add to selectbox"
4) when button is clicked (use onClick handler), add the content of the
textfield as the new value and text to the new option.

You must be able to figure the details out yourself. If not, go get a good
JS book. :)

Regards,
Erwin Moller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top