Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on ListBox Control

Status
Not open for further replies.

VentureNewBie

Programmer
Jul 17, 2001
4
IN
Hi!,
There are 2 Listboxes, and I'm populating one ListBox at run time and would like to know how to populate the other ListBox at the click of a button(Eg: The user would like to select all the items) and be populated NOT at the click of the ListBox.

The other case is when the user multi-selects the items and then clicks on a button

Please post your answers.
TIA,
VentureNewBie
 
This is the piece of code.

I would like to know how I can remove all the items from ListBox1 and populate the same items in ListBox2 when the user clicks on a button named "SelectAll"
<%@ Language=VBScript %>
<HTML>
<HEAD>
<LINK REL=&quot;stylesheet&quot; TYPE=&quot;text/css&quot; HREF=&quot;../tms.css&quot;>
<title>Trial Menu Page</title>
</HEAD>
<form name=TrialMenuPage method=post>
<BODY>

<%
Set oConn = Server.CreateObject(&quot;ADODB.Connection&quot;)

'This line creates an ADO Connection Object named oConn.
'To use the oConn ADO connection we must first open it:

oConn.Open(&quot;provider=SQLOLEDB.1;UserId=tmsuser;password=tms;Initial Catalog=TMS;data source=testing-tms;&quot;)

set oRs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
oRs.ActiveConnection = oConn
oRs.CursorType = 1
oRs.LockType = 1
oRs.Open &quot;SELECT BankID, BankShortName from BankMaster order by BankShortName&quot;

%>
<SCRIPT LANGUAGE=javascript>
<!--

/* Add groups selected from lstSelected list box to lstAvailable list box */

function Select_All()
{
/* Find selected items to add */
var cSelect = document.all.item(&quot;lstSelected&quot;); /* Listbox1 */
var cOut = document.all.item(&quot;lstAvailable&quot;); /* Listbox2 */

for (var i=0; i < cSelect.options.length; i++)
{
/* Check to see if a particular option is selected */
if(cSelect.options(i).selected)
{
/* Add new option to &quot;Groups Selected&quot; list box */
cOut.options[cOut.options.length]= new Option(cSelect.options(i).text, &quot;value &quot; + i);
cSelect.remove(i)
}
}
}


-->
</SCRIPT>


<center><h3>Trial Menu Page</h3></center>
<TABLE align=&quot;center&quot; border=0 cellPadding=1 cellSpacing=1 style=&quot;HEIGHT: 208px; WIDTH: 444px&quot;
width=&quot;75%&quot;>

<TR>
<TD><SELECT multiple id=lstAvailable name=lstAvailable size=2 style=&quot;HEIGHT: 204px; WIDTH: 186px&quot;>

</SELECT></TD>

<TD>
<P><INPUT id=btnSelectAll name=btnSelectAll type=button value=&quot;>>&quot; style=&quot;HEIGHT: 24px; WIDTH: 57px&quot; onclick=&quot;Select_All()&quot;></P>
<P><INPUT id=btnSelectOne name=btnSelectOne type=button value=&quot;>&quot; style=&quot;HEIGHT: 24px; WIDTH: 57px&quot; onclick=&quot;Select_One()&quot;></P>
<P><INPUT id=btnDeSelectAll name=btnDeSelectAll type=button value=&quot;<&quot; style=&quot;HEIGHT: 24px; WIDTH: 55px&quot; onclick=&quot;Deselect_One()&quot;></P>
<P><INPUT id=btnDeSelectOne name=btnDeSelectOne type=button value=&quot;<<&quot; style=&quot;HEIGHT: 24px; WIDTH: 57px&quot; onclick=&quot;Deselect_All()&quot;><br></P>
<CENTER> </CENTER>
</TD>
<TD><SELECT id=&quot;lstSelected&quot; name=&quot;lstSelected&quot; size=10 style=&quot;HEIGHT: 204px; WIDTH: 186px&quot; onclick=&quot;Select_All()&quot;>

<%while Not oRs.EOF%>

<OPTION value=&quot;<%=oRs.Fields(0).Value%>&quot; selected> <%=oRs.Fields(1).Value%></OPTION>

<%oRs.MoveNext()
wend
%>

</SELECT>
</TD>
</TR>
</TABLE>

<INPUT id=btnNext name=btnNext type=button value=Next style=&quot;HEIGHT: 24px; WIDTH: 54px&quot;> 
<INPUT id=btnFinish name=btnFinish type=button value=Finish>
</P>
<input type=&quot;hidden&quot; name=&quot;SelectFlag&quot;>
</BODY>
</form>
</HTML>









 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top