Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old May 5th, 2005, 12:53 AM
Authorized User
 
Join Date: Jun 2003
Location: Melbourne, Victoria, Australia.
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default Retrieving unselected items from a select box

Hi All,

Im having some trouble with a function im using.

I have created 2 List boxes on my form

1st Called AvailableCountries
2nd Export

I am using javascript to enable the user to select countries from the 1st list (AvailableCountries) and add it to the 2nd list box (Export).

All works well the only problem is now that i need to retrieve the options in the Export select box when the form has been submitted.

Because the items selected arn't selected like normal eg. <option value="US" selected>US</option>

You can just request.form("Export") because none have been selected.

How can i call in asp the options in the Export Field with ASP?

Thanks

Tim :)

TDA
__________________
TDA
  #2 (permalink)  
Old May 5th, 2005, 01:36 AM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

I had the need for a similar thing. It is cut n paste does just what you need it to do:
1..Save the following code to a .asp or .html page
2..Create another page at the same dir level and call it postTo.asp
3..Put this line in the postTo.asp page (the values you need):
<%= request.form("selectedValues") %>

--------------------------start-----------------------
<html>
<HEAD>
<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 not made any selections");
    }
    else {
    alert("Here are the values you've selected:\r\n" + strValues);
    document.choiceForm.selectedValues.value = strValues;
    choiceForm.submit();
        }
    }

//-->
</script>
</HEAD>
<BODY>
<form name="choiceForm" action="postTo.asp" method="post">
<input type="hidden" name="selectedValues" 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:<br><select multiple name="choiceBox" style="width:150;" size="10"></select></td>
 </tr>
 <tr>
  <td colspan=2 height=10><input type="button" value="Remove" onclick="removeMe();"><input type="button" value="Alert Then Post My Values" onclick="saveMe();"></td>
 </tr>
</table>
</form>
</body>
</html>

--------------------------finish----------------------

Wind is your friend
Matt
  #3 (permalink)  
Old May 5th, 2005, 02:22 AM
Authorized User
 
Join Date: Jun 2003
Location: Melbourne, Victoria, Australia.
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default

Thanks Matt

Works like a charm!

Tim :)



TDA


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fill select box and select recordset value markd Classic ASP Databases 1 February 20th, 2006 06:41 PM
Auto Select List Items JpJoe Access VBA 2 November 3rd, 2005 01:12 PM
Retrieving items from a table - Immediate Help badprogrammer Access VBA 2 May 4th, 2005 02:39 PM
Select Items in List from a String mwn1218 Access VBA 1 February 11th, 2005 11:21 AM
select box/List box alphabetic sort sasidhar79 Javascript How-To 3 November 10th, 2004 03:04 AM





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