Client-Side Scripting - Drop Down List

J

Jeremy S

When users select from a DropDownList, I'd like to have the selected value
get copied to a TextBox also on the same page.

1. How do I wire up a client-side JavaScript function call to a DropDownList
control so that the function gets called when the user makes a selection?
This DropDownList will be a server control because it gets populated
server-side.
2. What is the syntax I need to use in the client-side function that will
retrieve the value selected from the DDL?

Thanks!
 
P

Patrick Olurotimi Ige

Have ou tried the YourDropDownList_SelectedIndexChanged method with
AutoPostBack True?
 
J

Jeremy S

That won't help... I need for *client-side* function to be called.
AutoPostBack would work if I needed a server-side function to be called.
 
J

Jeremy S

Thank you very much! I'll give it a whirl.

-JS


Eliyahu Goldin said:
1&2: Put this tag
oncheck="txtBox.value=this.options[this.selectedIndex].value"
in your ddl definition in the html view.

Alternatively you can use it in the code (c#):
MyDdl.Attributes["onclick"] =
"txtBox.value=this.options[this.selectedIndex].value";

Eliyahu

Jeremy S said:
When users select from a DropDownList, I'd like to have the selected
value
get copied to a TextBox also on the same page.

1. How do I wire up a client-side JavaScript function call to a DropDownList
control so that the function gets called when the user makes a selection?
This DropDownList will be a server control because it gets populated
server-side.
2. What is the syntax I need to use in the client-side function that will
retrieve the value selected from the DDL?

Thanks!
 
E

Eliyahu Goldin

1&2: Put this tag
oncheck="txtBox.value=this.options[this.selectedIndex].value"
in your ddl definition in the html view.

Alternatively you can use it in the code (c#):
MyDdl.Attributes["onclick"] =
"txtBox.value=this.options[this.selectedIndex].value";

Eliyahu
 

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

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top