Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. 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 Databases 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 May 5th, 2004, 04:28 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default Assign 2 values to each Item in a Select Menu

Hi All,

Is there a way to assign more than 1 value to items in a select menu? In other words, a typical select menu would look something like this:

<select size="3" name="D1">
    <option VALUE="test">TEST</option>
    <option VALUE="test2">TEST2</option>
    <option VALUE="test3">TEST3</option>
</select>

What I want is something like:
<select size="3" name="D1">
    <option value="test" value2="diffValue">TEST</option>
    <option value="test2" value2="diffValue2">TEST2</option>
    <option value="test3" value2="diffValue3">TEST3</option>
  </select>

Is this even possible? Trust me, I have a really good reason for this, and it absolutely relates to ASP database. Here is why:

Database setup:
Menu1's Table Columns:
    Menu1DisplayName, Menu1Value, Menu1QueryString

Menu2's Table Columns:
    Menu2DisplayName, Menu2Value, Menu2QueryString

Here is the setup: Both Menu1 and Menu2 is populated by recordsets from the tables list above. Menu2 changes dynamically depending on what the user select from Menu1; the two menus are linked by the Menu#Value fields(I have this coded using JavaScript already, so it is not a problem). Menu2 is linked to Menu1 based on the Menu#Value field.

Anyway, when the user select an item from Menu1 AND Menu2, I want to be able to grab both the Menu1QueryString and Menu2QueryString. This way I can combine them to query the database with the data that I want.

Here is the problem, sine VALUE is populated by the Menu#Value fields from each tables(because this is how I link the 2 tables together), I don't know how to pull in the querystrings. This is why I want to know if I can have two values assigned to each items? If not, is there anyway I can grab the Querystrings from the tables? Please help. Any suggestions?

For more detailed question or my codes, you can email me directly.

Thanks you.

 
Old May 5th, 2004, 05:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

First of all, SELECT box(Combo box) doesn't support having 2 values per Item. So drop that plan of going for it. Other way is, you can use a DELIMITER for separating both the values.

<option value="MENU2VALUE:MENU2QueryString">MENU2DisplayNa me</option>

Then on selection, you can split the parts before and after ":" and act accordingly with the values.

This is one way.
__________________________

I assume that your Menu2's table should have something like this.

DisplayName, MENU2Value, MENU1Value, Menu2Querystring

Else add the MENU1Value in there. Otherwise it cannot be called that these 2 tables are linked.

So based on value selected from 1st List, you can always query the database to populate the 2nd list, which has value as MENU2VALUE for each item listed there.

Now, in the ONCHANGE even of 2nd list, you can query the database again to get the Querystring and proceed from there on. I dont see anyother better way of doing it.

Feel free to ask for any clarifications further.
Cheers!

-Vijay G
 
Old May 5th, 2004, 06:23 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi ViJay,

Thanks for the quick reply. I completely understand your explanations. But there is a problem. For the querystrings, they are very long. I have some that are at least 50+ characters long. Therefore, would it consider "bad" programming practice to separate with a delimiter? If not, how would I be able to separate the parts, before and after ":"

Regarding your second solution, maybe I was not as clear of how I populate my list menus. Menu1 is populated by a recordset I got from the Menu1 table. Menu2, i just put all the values in an array using JavaScript. This way i can make it change dynamically depending on what the users select form Menu1. MENU2Value is what link to MENU1Value, I just named them differently for easy explanation.

The hard part is how to grab the querystrings from the database, associated to each items. This way I can use these querystring to query a different table(the data table). In other words, the goal of this whole topic is to populate the two list menus, and then grab the necessary values(querstring). Since you mention there is no way to put 2 values in a menu list, then I have a problem b/c I don't know how to grab the querystrings.

The truly end result is to use these values(querystrings) to query a data table(which will be a different topic) I know this is a bit confusing, if you don't mind, I can attach my codes. It is not that long. Please let me know.

Thanks again for your time.

Leon




 
Old May 5th, 2004, 06:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Regarding the 1st solution, you can see help on string functions in javascript. There should be something called SPLIT function, using which you can specify the delimiter as ":" and that gives you an array as a result.

Regarding the 2nd solution, is it not possible in javascript to query the database on selection of a value from a list box? I haven't used that in javascript, as I always use ASP to do that. If it is possible with javascript too, here are the steps.

1) populate the MENU1 list box, with VALUE="MENU1Value"
2) On selection of an item from MENU1, query the database and get the relevant data for the selected value from MENU1.
3) Populate the MENU2 with the data queried based on selection in MENU1, with VALUE="MENU2QueryString". Skip the MENU2VALUE, as you said
Quote:
quote:MENU2Value is what link to MENU1Value, I just named them differently for easy explanation.
4) On selection of any Item from MENU2, using its Value as querystring, you can query the database for any records matching the querystring.

Hope it is clear now.

This can be done using ONCHANGE event on the list box
EG:
Code:
<script language="javascript">
function refreshWindow()
{
    if (document.frmMenu.cboMenu1.selectedIndex != 0)
    {
        window.location.href='THISFILENAME.asp?MenuValue=' + document.frmMenu.cboMenu1[document.frmMenu.cboMenu1.selectedIndex].value
    }
}
</script>

<Select name="mymenu" onchange="javascript:refreshWindow()">
    <option value="menu1value">......</option>
</Select>
This on selection of a value from list box refreshes the page with selected value and the value is sent as query string and use the querystring to query the database and populate the second Menu. Same way refresh the page on selection of Item from 2nd menu and use its value to query the database and act accordingly.

Hope that helps.
Cheers!

-Vijay G
 
Old May 5th, 2004, 06:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

<Select name="mymenu" onchange="javascript:refreshWindow()">
Please read it as
<Select name="cboMenu1" onchange="javascript:refreshWindow()">



-Vijay G





Similar Threads
Thread Thread Starter Forum Replies Last Post
assign numerical values to text ptrussell2009 Excel VBA 9 October 8th, 2017 04:38 AM
how create menubar, menu, menu item in xsl vijayanmsc XSLT 1 June 5th, 2006 06:43 AM
Menu Help in statusbar at mousemove over Menu item Kaustav VB Components 1 September 14th, 2005 09:28 AM
Use VBA to assign cell values eric_winters Excel VBA 2 September 3rd, 2004 02:27 PM





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