Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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:35 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, 07:54 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

this is more a ASP issue, try posting this in the classic ASP forum.

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
 
Old September 13th, 2005, 08:02 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Tulin,

If your SUPPLIER field in the db is an integer, you should be able to do this:
Code:
strOpenPO= "SELECT Count(PONUMBER) AS OpenPos FROM MyTable WHERE SUPPLIER IN(" & SSupp & ");"
HTH,

Chris

 
Old September 13th, 2005, 02:54 PM
Authorized User
 
Join Date: Aug 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My Supplier field is string...

Even though I tried the following query I got nothing.

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

It works fine if I select only one value from list box. My problem is that if I select more than one value...

Thanks.



 
Old September 14th, 2005, 02:02 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Life would be easier if you stuck to the method of having an integer ID for the supllier in the option value and the name as the text.
If you must stick to a string for both then:
  • Add quotes to your ASP otherwise if a supplier has a space your HTML will be invalid
    Code:
    <option value="<%=rsMain("Supplier Name")%>">
  • If you post a page with a multiple select the values appear as a comma delimited string in the Request.Form data, e.g: Supplier=Microsoft,IBM,Cisco. For your query to work you need to add single quotes to each supplier. Try this function:
    Code:
    'Turns "Microsoft,IBM,Cisco" into "'Microsoft','IBM','Cisco'"
    Function GetSqlList(Items)
      Dim sResult
      Dim iIndex
      Dim iCount
      Dim arrItems
      arrItems = Split(Items, ",")
      iCount = UBound(arrItems)
      For iIndex = 0 To iCount 
        sResult = sResult & "'" & arrItems(iIndex) & "'"
        If iIndex <> iCount Then
          sResult = sResult & "," 
        End If
      Next
      GetSqlList = sResult
    End Function

--

Joe (Microsoft MVP - XML)





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 Classic ASP Basics 4 September 13th, 2005 06:40 PM





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