Need some major help with listboxes

Results 1 to 2 of 2

Thread: Need some major help with listboxes

  1. #1
    Marvin Simon Guest

    Default Need some major help with listboxes

    Hi,<BR><BR>I found some cool code that&#039s exactly what I need. It involves the use of dual list boxes. It allows the user to get a list of available items and move these items to a selected list. The only problem I&#039ve been struggling with is that I need to modify this code to handle a product id as the hidden value field for the listbox and a product name that will be displayed to the user <BR>I&#039ve been struggling with this for awhile with no success. The code now only works with one value being used for the column value and the display value for the listbox. My list of products is coming from a database and I didn&#039t know how quite to attack modifying this code for my needs. Please help.<BR>The original author hasn&#039t replied. I&#039m dying here!!!<BR><BR>http://www.activeserverpages.com/learn/listdual.asp<BR><BR>Thanks<BR>Marvin<BR>

  2. #2
    Ben Jones Guest

    Default RE: Need some major help with listboxes

    I don&#039t have the time to rewrite the code for you, but this is an easy way to do what you want ...<BR><BR>Add some javascript to the top of the page. In it you will create two arrays. The first will be a listing of the primary key numbers to uniquely identify the string values you want to display. The second array will store the string values themselves.<BR><BR>Before you start the javascript it would be a good idea to know exactly how many items are going to be in the array. Supposing that the table you want to show the values from is called "products":<BR><BR>&#060;%<BR><BR>&#039 open dbase connection<BR>&#039 ...<BR><BR>sSQL = "SELECT count(product_ID) AS dbHits FROM products"<BR>set RS = Conn.Execute(sSQL)<BR>products = RS("dbHits")<BR><BR>&#037;&#062;<BR><BR>&#060;HTML ><BR>&#060;HEAD><BR>&#060;TITLE>&#060;/TITLE><BR>&#060;SCRIPT LANGUAGE="JAVASCRIPT"><BR>&#060;!--<BR><BR>// declare and size two arrays<BR>ar_product_ids = new array(&#060;%= products &#037;&#062;)<BR>ar_product_names = new array(&#060;%= products &#037;&#062;)<BR><BR>&#060;%<BR><BR>&#039 now perform the search to select the product IDs and products and populate the javascript with the approriate values<BR><BR>sSQL = "SELECT product_ID, product_name FROM products ORDER BY product_name"<BR>set RS = Conn.Execute(sSQL)<BR><BR>dbHits = 0<BR>do while RS.EOF = FALSE<BR> this_product_ID = RS("product_ID")<BR> this_product_name = RS("product_name")<BR> &#037;&#062;<BR> // set values for this product<BR> ar_product_ids[&#060;%= dbHits &#037;&#062;] = &#060;%= this_product_ID &#037;&#062;;<BR> ar_product_name[&#060;%= dbHits &#037;&#062;] = &#039&#060;%= this_product_name &#037;&#062;&#039;<BR> <BR> &#060;%<BR> dbHits = dbHits + 1<BR> RS.moveNext<BR>loop<BR><BR>&#037;&#062;<BR>--><BR>&#060;/SCRIPT><BR><BR>The last thing you need to do is modify the "onClick" statements in the select listbox (I&#039m assuming that&#039s how it works). If the syntax of the select is:<BR><BR>&#060;SELECT name="products_A" onClick="javascript:setProduct(this.value)"><BR>&# 060;option value="1">Toasters&#060;/option><BR>&#060;option value="2">Microwaves&#060;/option><BR>...<BR>&#060;/SELECT><BR><BR>Then when the person clicks "Toasters", it will send "1" to a javascript module called "setProducts" (note: javascript is case-sensitive). All you have to do is modify the Javascript code in the mode that gets called to:<BR><BR>1. loop from 0 to &#060;%= products &#037;&#062;<BR>2. check to see if the value received in the onClick is the same as the value in ar_product_ids[looping_variable_you_use]<BR>3. if it is, then add an item to the other listbox containing the product name, which you get from ar_product_names[looping_variable_you_use]<BR><BR>That&#039s it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •