Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 13th, 2009, 04:02 PM
Authorized User
 
Join Date: Apr 2009
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default moving items from one listbox to another

Can we implement listbox in Classic ASP where I can move items from one list box to another by clicking on a button ?
 
Old November 15th, 2009, 05:33 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

There are loads of code example out there for this. Your question is better suited in the JS area of the forum......Anyhow I used this a fair while ago. This moves the items from one multiple select area to another onclick. It is cut and paste code.

<html>
<HEAD>
<title>Mulitiple swap on click</title>
<SCRIPT LANGUAGE="JavaScript">
function moveOver()
{
var boxLength = document.choiceForm.choiceBox.length;
var selectedItem = document.choiceForm.available.selectedIndex;
var selectedText = document.choiceForm.available.options[selectedItem].text;
var selectedValue = document.choiceForm.available.options[selectedItem].value;
var i;
var isNew = true;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choiceForm.choiceBox.options[i].text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.choiceForm.choiceBox.options[boxLength] = newoption;
}
document.choiceForm.available.selectedIndex=-1;
}
function removeMe() {
var boxLength = document.choiceForm.choiceBox.length;
arrSelected = new Array();
var count = 0;
for (i = 0; i < boxLength; i++) {
if (document.choiceForm.choiceBox.options[i].selected) {
arrSelected[count] = document.choiceForm.choiceBox.options[i].value;
}
count++;
}
var x;
for (i = 0; i < boxLength; i++) {
for (x = 0; x < arrSelected.length; x++) {
if (document.choiceForm.choiceBox.options[i].value == arrSelected[x]) {
document.choiceForm.choiceBox.options[i] = null;
}
}
boxLength = document.choiceForm.choiceBox.length;
}
}
function saveMe() {
var strValues = "";
var boxLength = document.choiceForm.choiceBox.length;
var count = 0;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
if (count == 0) {
strValues = document.choiceForm.choiceBox.options[i].value;
}
else {
strValues = strValues + "," + document.choiceForm.choiceBox.options[i].value;
}
count++;
}
}
if (strValues.length == 0) {
alert("You have made no selection(s)");
}
else {
alert("Here are the values you've selected:\r\n" + strValues);
choiceForm.valuesForInsert.value = strValues;
choiceForm.submit();
}
}
//// adminGroups multiple select swap code finish
function validate()
{

if(document.choiceForm.groupname.value=="")
{
alert("You must enter a group name");
document.choiceForm.groupname.focus();
return(false);
}
if(document.choiceForm.gDescription.value=="")
{
alert("Please enter a brief description, you may edit this anytime");
document.choiceForm.gDescription.focus();
return(false);
}
saveMe();
//return (true);
}

function groupValidate()
{

if(document.adminGroupsComments.suggestionString.v alue=="")
{
alert("You must enter a suggestion");
document.adminGroupsComments.suggestionString.focu s();
return(false);
}
return (true);
}
</script>
</HEAD>
<BODY>
<form name="choiceForm" action="#" method="post">
<input type="hidden" name="selectedValues" value="0">
<input type="hidden" name="valuesForInsert" value="0">
<table border="0">
<tr>
<td valign="top" width=175>Available Countries:<br>
<select name="available" size=10 onchange="moveOver();">
<option value="1">Australia
<option value="2">New Zealand
<option value="3">USA
<option value="4">Canada
<option value="5">England
<option value="6">Switzerland
<option value="7">Russia
<option value="8">France
<option value="9">Italy
<option value="10">Samoa
</select></td>
<td valign="top">Your Choices:<input type="button" value="Remove" onclick="removeMe();"><br><select multiple name="choiceBox" style="width:150;" size="10"></select></td>
</tr>
<tr>
<td colspan=2 height=10><input type="button" value="Get Selected Values" onclick="saveMe();"></td>
</tr>
</table>
</form>
</body>
</html>
__________________
Wind is your friend
Matt
 
Old November 16th, 2009, 09:40 AM
Authorized User
 
Join Date: Apr 2009
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply but I want to retrive values for 1st listbox from database....Could you please help?
 
Old November 16th, 2009, 12:13 PM
Authorized User
 
Join Date: Apr 2009
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help....I fixed it...
 
Old November 16th, 2009, 05:41 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

No worries glad you sorted it.

If I may, a tip, be more clear with your question and you will more than likely get all your answers
__________________
Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
moving items from one listbox to another listbox Nishapd ASP.NET 3.5 Basics 2 December 3rd, 2009 07:20 AM
Getting all listbox items Lucy_H85 C# 2005 2 December 1st, 2009 05:36 AM
Moving Items up and down in a listbox Brendan Bartley Access 15 September 18th, 2007 06:42 AM
Unhighlight Listbox Items selevanm Access VBA 1 March 7th, 2007 01:39 PM
Moving Selected Items from a list box to excel AlanAtMars SQL Server 2000 2 August 19th, 2005 02:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.