Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Location
    Florida
    Posts
    9
    Thanks
    8
    Thanked 0 Times in 0 Posts

    How do you move a list of names from textbox to listbox

    I'm trying to move a list of names from a textbox (jim;bill;sam;cathy to a listbox. My code so will move the name to listbox but all one line. I need the list the names in the listbox so that can click them one at a time. Please see my code. How can I modify it to fill the list one name per line?



    function addItem(){
    var tb = $get('<%=txtWhoTo.ClientID%>');
    var rightListbox = document.getElementById('<%=lstNDisplay.ClientID%>');

    if(strText.length > 0){
    var nlength = rightListbox.options.length;
    rightListbox.options[nlength] = new Option(strText, nlength, false, false);
    }

    }

    I don't want remove any names from the listbox till I click the "OK" button and overwrite what is in the textbox.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,340 Times in 4,306 Posts
    Code:
    function moveToList()
    {
        var tb = document.getElementById('<%=txtWhoTo.ClientID%>');
        var sel = document.getElementById('<%=lstNDisplay.ClientID%>');
        var names = tb.value.split(";");
        for ( var n = 0; n < names.length; ++n ) 
        {
            var name = names[n].replace(/^\s+/,"").replace(/\s+$/,""); // trim each name
            sel.options[sel.options.length] = new Option(name,name);
        }
    }
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    bthumber (11-18-2010)

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Location
    Florida
    Posts
    9
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Boy oh boy this great stuff, this code is neat and clean. Along those lines how would I remove the names from the left listbox and the textbox?

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,075
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    Easiest way might be to reset the list and populate it again with the new information.

    Code:
    function ClearList() {
        var sel = document.getElementById('<%=lstNDisplay.ClientID%>');
        sel.options.length = 0;
    }
    Note: Unsure of PHP code <%...%>.

  • #5
    New to the CF scene
    Join Date
    Nov 2010
    Location
    Florida
    Posts
    9
    Thanks
    8
    Thanked 0 Times in 0 Posts
    function ClearList() {
    var sel = document.getElementById('<%=txtWhoTo.ClientID%>');
    sel.value = " ";
    }
    This is great for clearing my textbox which is one of the things I need to do, but when I move the names from the textbox to the rightListbox, how do I remove those names from leftListbox so that you don't have double names in the leftlistbox?

  • #6
    New to the CF scene
    Join Date
    Nov 2010
    Location
    Florida
    Posts
    9
    Thanks
    8
    Thanked 0 Times in 0 Posts
    First I had to move a list of names from a Textbox to the rightList (leftListbox and rightListbox). See code:

    function moveToList()
    {
    var tb = document.getElementById('<%=txtWhoTo.ClientID%>');
    var sel = document.getElementById('<%=lstNDisplay.ClientID%>');
    var names = tb.value.split(";");
    for ( var n = 0; n < names.length; ++n )
    {
    var name = names[n].replace(/^\s+/,"").replace(/\s+$/,""); // trim each name
    sel.options[sel.options.length] = new Option(name,name);
    }
    }

    Then I cleared the Textbox:

    function ClearList() {
    var sel = document.getElementById('<%=txtWhoTo.ClientID%>');
    sel.value = " ";
    }

    Now I have the list of names in the right listbox and left listbox. If the user clicks on a few names to put backin back in the leftListBox he/she get duplicate names in the leftListbox. Question...foreach name in rightListbox how can remove it from leftListbox?

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,340 Times in 4,306 Posts
    Can you show use your HTML page????

    Your first question was about a textbox (and there's no such thing in HTML, so I *assumed* you meant <input type="text") and a listbox (and there's not such thing in HTML, so I also assumed you meant <select>).

    But now you seem to be talking about two "listboxes", which I take to mean two <select>s.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,075
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Arrow

    Quote Originally Posted by Old Pedant View Post
    Can you show use your HTML page????

    Your first question was about a textbox (and there's no such thing in HTML, so I *assumed* you meant <input type="text") and a listbox (and there's not such thing in HTML, so I also assumed you meant <select>).

    But now you seem to be talking about two "listboxes", which I take to mean two <select>s.
    I think I'm glad to see someone who is as confused as I am!

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Quote Originally Posted by jmrker View Post
    Note: Unsure of PHP code <%...%>.
    That's not PHP. That's either ASP.NET, classic ASP, or JSP. But looking at the expression (txtWhoTo.ClientID) inside those delimiters, I'd say it's ASP.NET.

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,340 Times in 4,306 Posts
    Yes, clientId is an ASP.NET-ism.

    For reasons that are actually fairly sane, there are times when the ID used in the ASP.NET code doesn't match the ID in HTML code. So you can be sure you are getting the HTML ID this way.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #11
    New to the CF scene
    Join Date
    Nov 2010
    Location
    Florida
    Posts
    9
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I'm using asp.net C#. Here is the html:

    <td> style="width:10%; veritcal-align:Top" align="center>
    <input id="btnTo" type="button value="To" style="width:75px onclick="showPopup1()" /><td>
    <td style="width:90%; vertical-align:Top">
    <asp:Textbox Id="txtWhoTo" runat="Server" Width="90%" Height="23px" Textmode="multiline" />
    <input type="button" value="+" onclick="IncreaseTbSize()/>
    <input type="button" value="+" onclick="DecreaseTbSize()/>


    function showPopup1(){
    var button = document.getElementById("btnTo");
    button.disabled="disabled";
    var popup = document.getElementById("popupContent1");
    popup.style.display = "inline";

    moveToList();

    }

    <div id="popupContent1">
    <table...
    <tr>
    <td rowspan="4" valign="top">
    <asp:Listbox ID="lstNPicker" runat="Server" SelectionMode="multiple /><td>
    <asp:Listbox ID="lstNDisplay" runat="Server" SelectionMode="multiple /><td>
    <td><input id="btnPicker" type="button" value="-->" onclick="rightToLeft" >
    <td><input id="btnDisplay" type="button" value="<--" onclick="lefttoRight" >...



    The reason for the mix types is that I have fileupload controls on the page and as you know any postback will cause the files in the control to clear. The popup listbox is on the same page and populated from a list of names in a database.

    What I trying to do is after the user views the message and clicks the "reply to all" button and opens the createMessage page, the txtWhoTo textbox is filled with all of the recipents. If the user wishes to change some of the people in the list they need to click the to button bring up the listboxes. The name in the rightListbox should be the same as the names in the textbox. But the Leftlistbox should not the names that are in the rightListBox so if the user wishes to remove a recipent you will not get double name in the leftlistbox.

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,340 Times in 4,306 Posts
    Why bother with the textBox???

    Just show the list of names that will be sent to in the right Listbox. Show the additional people who *COULD* be sent to in the left Listbox. And then the user can move any number of names from left to right or vice versa. Whatever is in the right Listbox when the page is submitted is the final list.

    You could even hide the left listBox until the user hits a button requesting changes.

    I just don't see, at all, what the textBox adds to the human interface here. Seems to me it is, at best, confusing.

    The alternative, I suppose, would be use the textBox but then have a POPON <div> that appears to allow the left-right manipulation. But I think that showing all three--textbox and both listboxes--is confusing.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •