...

View Full Version : How do you move a list of names from textbox to listbox



bthumber
11-17-2010, 08:54 PM
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.

Old Pedant
11-17-2010, 09:51 PM
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);
}
}

bthumber
11-18-2010, 02:27 PM
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?

jmrker
11-18-2010, 04:04 PM
Easiest way might be to reset the list and populate it again with the new information.



function ClearList() {
var sel = document.getElementById('<%=lstNDisplay.ClientID%>');
sel.options.length = 0;
}


Note: Unsure of PHP code <%...%>.

bthumber
11-18-2010, 05:25 PM
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?

bthumber
11-18-2010, 06:55 PM
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?

Old Pedant
11-18-2010, 07:20 PM
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.

jmrker
11-19-2010, 12:28 AM
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! :eek:

glenngv
11-19-2010, 01:45 AM
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.

Old Pedant
11-19-2010, 02:07 AM
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.

bthumber
11-19-2010, 04:09 PM
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.

Old Pedant
11-19-2010, 07:23 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum