|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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 ;-) |
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Generating a combo box depending on the field selected in a former combo box |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|