tags:

views:

24

answers:

1

ok what i am trying to do is to add something in the textbox and after pressing the add button it should go into the select list. how would i do that with jquery?

I am not really able to make it work by your method .Please help? What i am doing wrong

<%= Html.ListBox("FeatureLists", ViewData["FeatureListListBox"] as MultiSelectList)%>

$("#add").click(function() { var val = $("#txtaddfeature").val(); alert("aaa"); $("", { 'value': val, text: val }).appendTo("#FeatureLists"); //$("#textbox").val(''); here if you want to clear the value for next time });
A: 

You can get the value using .val(), create the <option> using $() and append it to the <select> using .appendTo(), like this:

$("#addBtn").click(function() {
  var val = $("#textbox").val();
  $("<option />", { 'value': val, text: val }).appendTo("#selectList");
  //$("#textbox").val(''); here if you want to clear the value for next time
});
Nick Craver