navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

Multiple selections in drop down list

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> Multiple selections in drop down list
Page: [1]
 
RRogers123

 

Posts: 115
From: None
Status: offline

 
Multiple selections in drop down list - 3/8/2002 19:54:45   
I've seen some posts on this but I can't get it to work. I have a drop down list populated using DRW and multiple selections are allowed. If multiple items are selected, the query returns no records because no records match the whole string. How do you break it up into individual items in the SQL query? Thanks.

 
Spooky

 

Posts: 26599
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Multiple selections in drop down list - 3/8/2002 23:17:21   
The trick is to use "IN" as a query.
It does really demand specific column values, as you cant do a LIKE IN()

So ideally the values will be short text or numeric.

The numeric syntax is "....where column IN (1,2,3,4,5) "
Text : "....where column IN ('a','b','c','d') "

The DRW syntax would then be :
"....where column IN (::Input::)"

Now, the problem lies in passing text. Normally a multiple text box with text values will pass a comma delimited string.
While this is great for numbers, it is not good for text.

So what we need to do, is fool the DRW by enclosing our text VALUES in quotes.

<option value=" ' Text ' ">Option Text</option>

When a user selects multiple text items, they are passed to the DRW with quotes, all ready for the IN query.


§þððk¥
Database / DRW Q & A
VP-ASP Shopping cart
Spooky Login

(in reply to RRogers123)
RRogers123

 

Posts: 115
From: None
Status: offline

 
RE: Multiple selections in drop down list - 3/9/2002 9:23:18   
Thanks for your reply, but I still don't quite get it. My query looks like this:
SELECT * FROM Databasename WHERE (Week = '::Week::' AND Grade = '::Grade::' AND CourseNo = '::CourseNo::')
The week and the grade are static drop down lists from which only one item is selected. The CourseNo is also a dropdown list box populated using DRW with grade in the query. Multiple items can be selected for CourseNo. After the user selects the week and grade, the CourseNo listbox is filled with the appropriate values. The CourseNo are actually numbers but are defined as text in the Access database. Does IN replace the = operator? How do I modify the SQL? Thanks for your help.


(in reply to RRogers123)
Spooky

 

Posts: 26599
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Multiple selections in drop down list - 3/9/2002 21:35:48   
Reading between the lines ....

"....CourseNo IN (::CourseNo::))"

You would need to ensure, if its a text field, that the DRW is 'tricked' as I suggested using quotes in the list values.


§þððk¥
Database / DRW Q & A
VP-ASP Shopping cart
Spooky Login

(in reply to RRogers123)
RRogers123

 

Posts: 115
From: None
Status: offline

 
RE: Multiple selections in drop down list - 3/10/2002 12:38:40   
Thanks. I got it to work.


(in reply to RRogers123)
R Clark

 

Posts: 161
From: USA
Status: offline

 
Spooky?: Multiple selections in drop down list - 4/26/2005 12:16:10   
Spooky,
I've got the scenario in the above post working for my page (thanks). I'd just like to do one more thing and that is retain the selections after submitting the query.
Typically I would use something like...
<option  value="'<%=FP_FieldHTML(fp_rs,"ata")%>'" <%if request.form("atadd") = fp_fieldhtml(fp_rs,"ata") then response.write "selected"%>>ATA <%=FP_FieldHTML(fp_rs,"ata")%></option>

The single quotes around the 'value' in the line of code are additional for the scenario this post originally addressed, so I don't know if that is affecting the statement and its ability to retain the selections (in a single select dd I don't have the single quotes and it would retain the selection) or...
maybe you can't retain multiple selections (easily anyway) in a 'select multiple' situation?

I sure hope I'm making sense!
many thanks!
Randy

(in reply to RRogers123)
BeTheBall

 

Posts: 6359
Joined: 6/21/2002
From: West Point Utah USA
Status: offline

 
RE: Spooky?: Multiple selections in drop down list - 4/26/2005 12:35:51   
See if this works:
<option value="'<%=FP_FieldHTML(fp_rs,"ata")%>'" <%if Instr(request.form("atadd"), fp_fieldhtml(fp_rs,"ata")) then response.write " selected"%>>ATA <%=FP_FieldHTML(fp_rs,"ata")%></option>[/code]


_____________________________

Duane

Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.

(in reply to R Clark)
R Clark

 

Posts: 161
From: USA
Status: offline

 
RE: Spooky?: Multiple selections in drop down list - 4/26/2005 12:45:08   
Works perfectly! :)

To educate myself (because I'm very much about learning this, not just copying and pasting your wisdom), whats the instr and the comma and the space before selected doing? (I think I caught everything you did)

again! many thanks!
Randy

(in reply to BeTheBall)
rdouglass

 

Posts: 9227
From: Biddeford, ME USA
Status: offline

 
RE: Spooky?: Multiple selections in drop down list - 4/26/2005 14:19:18   
quote:

whats the instr and the comma and the space before selected doing?


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctinstr.asp

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to R Clark)
BeTheBall

 

Posts: 6359
Joined: 6/21/2002
From: West Point Utah USA
Status: offline

 
RE: Spooky?: Multiple selections in drop down list - 4/26/2005 15:23:54   
Instr is a function.  The first value after the function is the string to be searched.  The value after the comma is the value you are looking for.  It is a true/false type argument.  For example:

Instr("Hello World","Hello") would be true.

The space in front of selected is necessary because without it ASP will write out optionselected instead of option selected.

Is that any clearer?


_____________________________

Duane

Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.

(in reply to rdouglass)
R Clark

 

Posts: 161
From: USA
Status: offline

 
RE: Spooky?: Multiple selections in drop down list - 4/26/2005 15:35:56   
yes, Thank you both!

(in reply to BeTheBall)
rdouglass

 

Posts: 9227
From: Biddeford, ME USA
Status: offline

 
RE: Spooky?: Multiple selections in drop down list - 4/26/2005 16:07:42   
quote:

Instr("Hello World","Hello") would be true.


Actually, I believe it would return 1.  Instr returns an integer based on the position in the string where the searched-for-text is found first.  If not found, it returns a 0. So this:

Instr("Hello World","o")

would return 5 and never 8.

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to BeTheBall)
BeTheBall

 

Posts: 6359
Joined: 6/21/2002
From: West Point Utah USA
Status: offline

 
RE: Spooky?: Multiple selections in drop down list - 4/26/2005 16:58:43   
quote:

ORIGINAL: rdouglass

quote:

Instr("Hello World","Hello") would be true.


Actually, I believe it would return 1.  Instr returns an integer based on the position in the string where the searched-for-text is found first.  If not found, it returns a 0. So this:

Instr("Hello World","o")

would return 5 and never 8.


I stand corrected.  rdouglass' analysis is 100% accurate.  I guess my point was that if you for example use this:

<%
If Instr("Hello World","Hello") Then
Response.write("True")
Else
Response.Write("False")
End If
%>

It will write "True"

On the other hand, this:

<%
If Instr("Hello World","Jello") Then
Response.write("True")
Else
Response.Write("False")
End If
%>

Will write "False"

_____________________________

Duane

Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.

(in reply to rdouglass)
Page:   [1]

All Forums >> Web Development >> ASP and Database >> Multiple selections in drop down list
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts