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 September 12th, 2005, 05:41 PM
Authorized User
 
Join Date: Aug 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default passing values from multiple list box

Hello everyone,

I am really having hard time to retrieve data from database using multiple list box. Here is the my simplified version of codes that you may want to take look...

<select NAME="Supplier" SIZE=4 MULTIPLE >
<%While NOT rsMain.EOF%>
<option value=<%=rsMain("Supplier Name")%>><%=rsMain("Supplier Name")%></option>
<%rsMain.MoveNext()
Wend%>
</select>


<INPUT TYPE="BUTTON" NAME="open" VALUE="SUBMIT" ONCLICK="outputSelected(this.form.Supplier.options )">

<SCRIPT LANGUAGE="JavaScript">

   function getSelected(opt) {
      var selected = new Array();
      var index = 0;
      for (var intLoop=0; intLoop < opt.length; intLoop++) {
         if (opt[intLoop].selected) {
            index = selected.length;
            selected[index] = new Object;
            selected[index].value = opt[intLoop].value;
            selected[index].index = intLoop;
         }
      }
      return selected;
   }

         function outputSelected(opt) {
            var sel = getSelected(opt);
            var strSel = "";
            for (var item in sel)
            //alert (sel[item].value)
               strSel += sel[item].value + "\n";
               alert("Selected Items:\n" + strSel);
            window.location='SupplierFilterTest.asp?Supp=' + strSel;

         }
      </SCRIPT>

<%SSupp= Request("Supp")%>

strOpenPO= "SELECT Count(PONUMBER) AS OpenPos FROM MyTable WHERE SUPPLIER ='" &SSupp& "'"

When I take a look inside SSupp, all variables are appending each other without any space.

When I select only one value from list box, my code is working fine. But whenever I select more than one, I get nothing.

Any help would be appreciated,

Thanks,

-Tulin


 
Old September 13th, 2005, 09:20 AM
Authorized User
 
Join Date: Jul 2005
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did you try the keyword IN?
ie.

"SELECT Count(PONUMBER) AS OpenPos FROM MyTable WHERE SUPPLIER
in (" &SSupp& ")"


 
Old September 13th, 2005, 11:34 AM
Authorized User
 
Join Date: Aug 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It doesn't work. I tried everything "LIKE ,IN" ...

My main problem is that I can't diffrentiate suppliers. They are appending each other without any space. For example, I get Supplier1, Supplier2, Supplier3 from Javascript code. But when pass the values to asp with <%SSupp= Request("Supp")%> code,
I get SSupp= Supplier1Supplier2Supplier3. I used replace function, but i can't successful.

Any suggestion would be appreciated.

Thanks...





 
Old September 13th, 2005, 11:35 AM
Authorized User
 
Join Date: Aug 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It doesn't work. I tried everything "LIKE ,IN" ...

My main problem is that I can't diffrentiate suppliers. They are appending each other without any space. For example, I get Supplier1, Supplier2, Supplier3 from Javascript code. But when pass the values to asp with <%SSupp= Request("Supp")%> code,
I get SSupp= Supplier1Supplier2Supplier3. I used replace function, but i can't successful.

Any suggestion would be appreciated.

Thanks...


 
Old September 13th, 2005, 06:40 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

;;;It doesn't work. I tried everything "LIKE ,IN" ...
print your query to the browser and post it


You should have a commer delimited string of integers in the SSupp value to use IN.

rsMain("Supplier Name") doesnt sound like an integer to me.

BTW : why would you want to retrieve these values on the client side

IMO you should place the unique ID (auto incrimenting integer)which should be your primary key in the value of each of your items in the multiple select list. When they get posted the value will lokk like:
1,5,7,9
Then do your SELECT WHERE IN statement.

If you dont have a unique identifyer for each of your records to do such a thing, create one. Even if you dont need it, put it there. There is a good chance you may need it in the future for updating, deleting, inactivating, archiving records etc.

Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 10:33 PM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
passing values from multiple list box tulincim Classic ASP Databases 22 October 6th, 2005 01:16 PM
passing values from multiple list box tulincim Javascript 4 September 14th, 2005 02:02 AM





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