Sam
Sam

Reputation: 105

populate a clientside dropdown with a server side dropdown in aspx page using jquery/javascript

I am trying to populate a clientside dropdown with a server side dropdown in aspx page with the following syntax. But this does not seem to do anything.

$('#' + '<%= ddClassMain.ClientID %>').find("select").clone().appendTo($('ddClass01'))

I have embedded this in a javascript function which gets triggered onchange() event of another clientside textbox.

I know that select is not a property of aspx dropdown. But using find("ListItem") also does not seem to work. Please feel free to suggest a solution or workaround.

Upvotes: 0

Views: 374

Answers (2)

IUnknown
IUnknown

Reputation: 22448

$('#<%= ddClassMain.ClientID %> > option').clone().appendTo("#ddClass01");

With this selector expression you've select all children option elements of the ddClassMain select control. The find('select') method just pointless here since you don't need to copy whole dropdown to ddClass01 but only his options.

Upvotes: 2

scessor
scessor

Reputation: 16115

I think the parameter in the appendTo has a wrong selector. Is ddClass01 a class, then use $('.ddClass01'). If ddClass01 is an id, then use $('#ddClass01').

Upvotes: 1

Related Questions