mutiple addition/remove in two listboxes

Discussion in 'ASP .Net Web Controls' started by deepak, Feb 16, 2005.

  1. deepak

    deepak Guest

    i want to add and remove mutiple selected values in first list box(html
    control) to another(html control) at the same time after clicking a
    bttuonsay(Button1,html control) and remove mutiple selected text in another
    list box after cliking another button(Button2,html control) ..
    my script is given below
    ...........
    <script language=javascript>
    function doDetail(Action)
    {
    switch(Action)
    {
    case 'Add':
    var lstFrom = document.getElementById("lstFrom");
    var lstTo = document.getElementById("lstTo");
    if(document.Form1.lstFrom.selectedIndex == -1)
    {
    alert('Please select atleast one record to Add');
    return;

    }
    else
    {
    var o = document.createElement("option");
    var selIndex = lstFrom.selectedIndex;
    o.text = lstFrom.options[selIndex].text;
    o.value = lstFrom.options[selIndex].value;
    var i=0;
    for (i = 0; i <=lstFrom.selectedIndex; i++)
    {
    alert(i);
    }
    document.getElementById("lstTo").add(o);
    }
    break;

    case 'Remove':

    //var lstFrom = document.getElementById("lstTo");
    //var lstTo = document.getElementById("lstFrom");
    if(document.Form1.lstTo.selectedIndex == -1)
    {
    alert('Please select atleast one record to Remove');
    return;
    }
    else
    {

    var o = document.createElement("option");
    var selIndex = lstTo.selectedIndex;
    o.text = lstTo.options[selIndex].text;
    o.value = lstTo.options[selIndex].value;
    document.getElementById("lstTo").remove(lstTo.selectedIndex);


    // document.getElementById("lstTo").remove(new Option
    ("o.text","o.value"));
    document.getElementById("lstFrom").add(o);

    }
    break;

    }
    }
    </script>
    .........................................
    rivate Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here

    Button1.Attributes("OnClick") = "javascript:doDetail(this.value);"
    Button2.Attributes("OnClick") = "javascript:doDetail(this.value);"





    If Page.IsPostBack = False Then
    fnFillListBox()


    End If
    End Sub
    .........................................

    help me
     
    deepak, Feb 16, 2005
    #1
    1. Advertising

  2. It sounds like you're trying to do something like this:

    http://www.metabuilders.com/Tools/DualList.aspx

    "deepak" <> wrote in message
    news:...
    >i want to add and remove mutiple selected values in first list box(html
    > control) to another(html control) at the same time after clicking a
    > bttuonsay(Button1,html control) and remove mutiple selected text in
    > another
    > list box after cliking another button(Button2,html control) ..
    > my script is given below
    > ..........
    > <script language=javascript>
    > function doDetail(Action)
    > {
    > switch(Action)
    > {
    > case 'Add':
    > var lstFrom = document.getElementById("lstFrom");
    > var lstTo = document.getElementById("lstTo");
    > if(document.Form1.lstFrom.selectedIndex == -1)
    > {
    > alert('Please select atleast one record to Add');
    > return;
    >
    > }
    > else
    > {
    > var o = document.createElement("option");
    > var selIndex = lstFrom.selectedIndex;
    > o.text = lstFrom.options[selIndex].text;
    > o.value = lstFrom.options[selIndex].value;
    > var i=0;
    > for (i = 0; i <=lstFrom.selectedIndex; i++)
    > {
    > alert(i);
    > }
    > document.getElementById("lstTo").add(o);
    > }
    > break;
    >
    > case 'Remove':
    >
    > //var lstFrom = document.getElementById("lstTo");
    > //var lstTo = document.getElementById("lstFrom");
    > if(document.Form1.lstTo.selectedIndex == -1)
    > {
    > alert('Please select atleast one record to Remove');
    > return;
    > }
    > else
    > {
    >
    > var o = document.createElement("option");
    > var selIndex = lstTo.selectedIndex;
    > o.text = lstTo.options[selIndex].text;
    > o.value = lstTo.options[selIndex].value;
    > document.getElementById("lstTo").remove(lstTo.selectedIndex);
    >
    >
    > // document.getElementById("lstTo").remove(new Option
    > ("o.text","o.value"));
    > document.getElementById("lstFrom").add(o);
    >
    > }
    > break;
    >
    > }
    > }
    > </script>
    > ........................................
    > rivate Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > 'Put user code to initialize the page here
    >
    > Button1.Attributes("OnClick") = "javascript:doDetail(this.value);"
    > Button2.Attributes("OnClick") = "javascript:doDetail(this.value);"
    >
    >
    >
    >
    >
    > If Page.IsPostBack = False Then
    > fnFillListBox()
    >
    >
    > End If
    > End Sub
    > ........................................
    >
    > help me
     
    Ken Cox [Microsoft MVP], Feb 16, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?ZGVlcGFr?=

    add/remove with javascript for listboxes

    =?Utf-8?B?ZGVlcGFr?=, Feb 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    18,241
    KingLordSon
    Apr 20, 2007
  2. =?Utf-8?B?ZGVlcGFr?=

    mutiple additon/remove in listboxex using javascript

    =?Utf-8?B?ZGVlcGFr?=, Feb 16, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    396
    =?Utf-8?B?ZGVlcGFr?=
    Feb 16, 2005
  3. Jeffrey Barish
    Replies:
    0
    Views:
    293
    Jeffrey Barish
    Apr 19, 2004
  4. ASPirant

    moving items between two listboxes

    ASPirant, Nov 22, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    99
    ASPirant
    Nov 22, 2005
  5. ASPirant

    Transfer between two listboxes

    ASPirant, Nov 22, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    140
    ASPirant
    Nov 22, 2005
Loading...

Share This Page