javascript add values to list box

Posted by Shalini under ASP.NET on 6/10/2008 | Views : 2213 | Status : [Member] | Replies : 1

I have a form, and in this form, there are 2 drop down menu, and a text box ,two buttons (labelled "add" and "remove") and finally, a listbox.

The question is, when the user clicks on the add button, how do I add the value selected in the drop down list and text bopx value and put it into the listbox? After adding to the listbox, the selected value needs to stay in the drop down menu and not get removed. When the remove button is pressed, the selected value from the listbox just needs to disappear from the listbox and not the drop down menu.

Thanks in advance



Posted by: Dongavipul on: 6/19/2008 [Member] Starter

it is simple you call one function at client side like this way
function addValue()
// For getting value from dropdown
var Combo = document.getElementById('ddlTest');
var list = document.getElementById('lstTest');
if (Combo.value != "0")
list .options[list.selectedIndex].value= Combo.options[Combo.selectedIndex].text;

// For getting value from textbox
var txt= document.getElementById('txt');
function addValue()
var lst= document.getElementById('lstTest');

<asp:Button id="btnAdd" runat="Server" onclientClick="return addValue()"/>
<asp:Button id="btnRemove" runat="Server" onclientClick="return removeValue()"/>

Shalini, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response