views:

32

answers:

1

Hey guys, i'm not sure if was able to explain the at the title, but here's what I need:

I'm making a kind of dropdown menu, and I need to make a List, getting via datasource (function already there) the names of all cities from my database, then when the user clicks the name of a city, this name goes right to a textbox.

I'm not very familiar with jQuery, but I'll accept solutions using it.

+2  A: 

on the dropdown control: OnClientClick="fillTextBox()"

function fillTextBox() {
   var dropdownId = '#<%=DropDown1.ClientID%>';
   $("#mytextbox").val($(dropdownId + " option:selected").text());
}

this gets the actual city name, the value is a simple val() instead of text()

F.Aquino
This would get the text to the textbox, but first I need to Create THE clickable list with city names (getting them from datasource)
Vitor Reis
+1 - You could probably tighten-up the code by passing `this` to the fillTextBox function: `OnClientClick="fillTextBox(this);"` That way you wouldn't have to use the server-side script of the `ClientID`.
CAbbott
indeed CAbbott, I was unable to test (posted from my phone) so I went safemode.
F.Aquino
Vitor, you can create the Clicable list as a asp:DropDownList if you are in WebForms or a normal select in html with a for loop in your datasource creating the options if you are using MVC. If you want to consume the data with jquery (a getCitiesInJSON service for example) you need something like: http://stackoverflow.com/questions/1885816
F.Aquino