views:

40

answers:

1

Hi, I am using master page where i need to move value of one lisbox to the other with the help of Jquey i tried many ways but wasn't able to hit the nail. the methods i tried are as follows.

$("[id$='ModuleMasterListBox option:[@selected]']").appendTo($("[id$='ModuleSelectListBox']"));

$("[id$='ModuleMasterListBox option:@selected]'").appendTo($("[id$='ModuleSelectListBox']"));

var module = $("[id$='ModuleMasterListBox']").val();
module.appendTo($("[id$='ModuleSelectListBox']"));

these are the methods i tried which failed pls help me out....

A: 

You should be able to do it like this:

$("[id$='ModuleMasterListBox'] :selected").appendTo("[id$='ModuleSelectListBox']");

From your markup and the @ sign it looks like you're using an outdated version of jQuery, you may want to consider upgrading. In the above we're using the attribute-ends-with selector to get the <select> the using :selected to grab the selected <option> before moving it.

Keep in mind since it looks like you're using ASP.Net this will by default throw validation errors on the server-side, you'll have to disable page validation for it to allow items it didn't bind.

Nick Craver
Thanks it works fine......