ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old July 21st, 2003, 08:07 AM
tipy tipy is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 22 tipy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Generating a combo box depending on the field selected in a former combo box

I 'm trying to display a combo box (which datas are coming from a database) depending on the select of another combo box in the same form.
I think I should use the property onChange of JavaScript but don't know what to give in parameters.
In fact, I have an ASP function which generate a table containing the Strings obtained thanks to a request in a database. Then I'd like to put the Strings contained in the table, to a combo box. The combo box should refresh each time the user select another field in the former list.
It must be developped dynamically.
If you know any thorough web sites about this, great to indicate.

Reply With Quote
  #2  
Old July 21st, 2003, 10:55 AM
r0ssta r0ssta is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Charlottesville, VA
Posts: 57 r0ssta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 11 sec
Reputation Power: 6
Send a message via AIM to r0ssta
I'm looking to do almost the exact same thing.. currently looking all around now.. will post if I find anything.
__________________
Ross
ross@virginia.edu
www.rossgilmore.com

Reply With Quote
  #3  
Old July 30th, 2003, 06:49 AM
tipy tipy is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 22 tipy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I have found something in Javascript to answer my own question :-)
If you've nothin' against french language, go and see this url :
http://www.developpez.net/forums/viewtopic.php?t=8659
Enjoy!
And if any translation problem, you can ask ;-)

Reply With Quote
  #4  
Old July 30th, 2003, 08:43 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Maybe you did find what you wanted on that french site but I'll still post a reply for others in case they want to read/know.

In order to acheive what the posters wanted you can chose between 2 ways to do it. In fact I've seen 3 different ways but the third one isn't really important and I might, if asked, post it.

#1
-----
The idea behind the first approach is to dynamically build your first combobox in a way that when the user selects an item from the combobox, it *REFRESH's* the page and loads/creates the second combobox.

The downside to this approach is that a REFRESH occurs and that can be annoying for users on a 56k modem, or just simply annoying to anyone.

The good thing about this approach is that you don't/can't load a combobox having 1000 records in it cause the scroll bar of the combobox will be so tiny that your users won't look at all the list items and it might take a long time for the page to load since it must create a combobox with 1000 records in it.

While building your first combobox, you'll need to have an onchange attribute. The onchange should look something like:

<select name="slcName" onchange="MyFunction(this.options[selectedIndex].value)">
<option value="AAA">AAA</option>
<option value="BBB">BBB</option>
. . .
</select>

Now you can create the javascript function MyFunction() inside the <head>...</head> portion of your page. The function *should* submit the page to itself, this way, we can retrieve what the user selected and the Query the database to build are second combobox.

The function should look something like:
MyFunction(TheChosenValue)
{
document.location.href = "pageName.asp?CV=" + TheChosenValue
}

NOTE: I've given the name pageName.asp but that will obviously vary with what you have. I've also create a QueryString parameter called CV (short for Criteria Value).

Now at the beginning of pageName.asp you should have something like:

<%@ Language=VBScript %>

<%
Dim str_Is_There_A_Value

str_Is_There_A_Value = Trim(Request.QueryString("CV"))
'FOR DEBUG ONLY
'Response.Write "-->" & str_Is_There_A_Value & "<--"
'Response.End


'Validation of the value in the QueryString
If str_Is_There_A_Value = "" Then
'...We know the user didn't chose an item from the combobox
'...So we can assume that it's its first visit.

'Create the code that builds the first combobox with the onChange attribute

Else
'...Something was chosen by the user so let's query the database
'...with it

strSql = "blah blah.......WHERE blah ='" & str_Is_There_A_Value & "'"

'...Query the database and build the second combobox
End If

NOTE: I've assumed that the WHERE clause would be looking at a string value but it could've been a numeric one
%>

so that's it for the first approach, although I haven't shown the entire code and what not but you should get the idea...





#2
-----
I won't spend as much time explaining the second approach as you'll find plenty of example if you search google.com

but the idea behind #2 is to *AVOID* a refresh when the user choses an item in the first combobox.

The advantage of the this approach is that no REFRESH's is involved, its quick and fun for the user.

The cons are that the page CAN take forever to load since you must load *ALL THE POSSIBLE COMBIANTIONS/VALUES*

What needs to be done is to create javascript arrays.
The first combobox will still have an onchange attribute but wont refresh the page, in fact it'll get the value(s) for the second combobox from the javascript array.

That's it for the second approach

The link provided by tipy shows, in french, the javascript approach


Hope this helps!
Sincerely

Vlince

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Generating a combo box depending on the field selected in a former combo box


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway