Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." 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 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 28th, 2008, 08:51 PM
Authorized User
 
Join Date: Apr 2008
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with dynamic drop down lists

On my asp page I have 3 forms, each with two drop down lists. Of those two ddls, on each form, one is dependent on the other for population.

I got the dynamic population effect to work, but the problem is the page refreshes after each selection. This clears the information from previous ddl selections. How can I save the ddl selections even after the page refreshes (up to three times) so I can use them to create sql queries after all selections have been made?

I realize the way this works isn't ideal, but I'd like to use it, since it's fairly simple so far. There is very little data being moved around (and always will be), so the page reloads are very quick.

Reply With Quote
  #2 (permalink)  
Old April 29th, 2008, 05:07 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Hi,

Can you paste the code which is being used?



Om Prakash
Reply With Quote
  #3 (permalink)  
Old April 29th, 2008, 08:36 AM
Authorized User
 
Join Date: Apr 2008
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, here is the code

Code:
<%@ Language = VBscript %>
<% Option Explicit %>

<% Response.Buffer = True %>


<html>
<head>

<SCRIPT language=JavaScript>

function reload(form){
var val=form.xclass.options[form.xclass.options.selectedIndex].value;
self.location='mll.asp?xclass=' + val ;
}

function areload(form){
var aval=form.axclass.options[form.axclass.options.selectedIndex].value;
self.location='mll.asp?axclass=' + aval ;
}

function breload(form){
var bval=form.bxclass.options[form.bxclass.options.selectedIndex].value;
self.location='mll.asp?bxclass=' + bval ;
}

</script>
</head>
<body>
The idea behind this is to allow the user to be able to select three different classes<br>
and then click a "submit" button to run hardcoded sql statements to compare statistics<br> between the three groups. 
<%

'=========================
'first set of ddls
'=========================

Dim objconn,objRS,strSQL,xclass
xclass=Request.QueryString("xclass")
Set objconn = Server.CreateObject("ADODB.Connection")
objconn.ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("Series6.mdb")
objconn.Open
Set objRs = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT distinct class from s6test"
objRS.Open strSQL, objconn
Response.Write "<form method=post name=f1 action=dll.asp target="_self"><select name=xclass onchange='reload(this.form)'><option value=''>Class</option>"
Do While Not objRS.EOF 
Response.Write "<option value=" & objRs("class") & ">" & objRs("class") & "</option>"
objRS.MoveNext
Loop
objRs.Close
Response.Write "</select>"
Response.Write "&nbsp;&nbsp;"

If len(xclass) > 1 Then
strSQL = "SELECT distinct classmd FROM s6test where class='" & xclass & "';"
objRS.Open strSQL, objconn
Response.write "<select name=select2><option value=''>Month/Day</option>"    
Do While Not objRS.EOF 
Response.Write "<option value=" & objRs("classmd") & ">" & objRs("classmd") & "</option>"
objRS.MoveNext
Loop
Response.Write "</form>"
response.write "</select>"
objRs.Close
objconn.Close
end if
Response.write "<br><br>" 

'====================
'second set of ddls
'====================

Dim aobjconn,aobjRS,astrSQL,axclass
axclass=Request.QueryString("axclass")
Set aobjconn = Server.CreateObject("ADODB.Connection")
aobjconn.ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("Series6.mdb")
aobjconn.Open
Set aobjRs = Server.CreateObject("ADODB.Recordset")
astrSQL = "SELECT distinct class from s6test"
aobjRS.Open astrSQL, aobjconn
Response.Write "<form method=post name=f2 action=''><select name=axclass onchange='areload(this.form)'><option value=''>Class</option>"
Do While Not aobjRS.EOF 
Response.Write "<option value=" & aobjRs("class") & ">" & aobjRs("class") & "</option>"
aobjRS.MoveNext
Loop
aobjRs.Close
Response.Write "</select>"
Response.Write "&nbsp;&nbsp;"

If len(axclass) > 1 Then
astrSQL = "SELECT distinct classmd FROM s6test where class='" & axclass & "';"
aobjRS.Open astrSQL, aobjconn
Response.write "<select name=select3><option value=''>Month/Day</option>"    
Do While Not aobjRS.EOF 
Response.Write "<option value=" & aobjRs("classmd") & ">" & aobjRs("classmd") & "</option>"
aobjRS.MoveNext
Loop
Response.Write "</form>"
response.write "</select>"
aobjRs.Close
aobjconn.Close
end if 
response.write "<br><br>"

'====================
'Third set of ddls
'====================

Dim bobjconn,bobjRS,bstrSQL,bxclass
bxclass=Request.QueryString("bxclass")
Set bobjconn = Server.CreateObject("ADODB.Connection")
bobjconn.ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("Series6.mdb")
bobjconn.Open
Set bobjRs = Server.CreateObject("ADODB.Recordset")
bstrSQL = "SELECT distinct class from s6test"
bobjRS.Open bstrSQL, bobjconn
Response.Write "<form method=post name=f2 action=''><select name=bxclass onchange='breload(this.form)'><option value=''>Class</option>"
Do While Not bobjRS.EOF 
Response.Write "<option value=" & bobjRs("class") & ">" & bobjRs("class") & "</option>"
bobjRS.MoveNext
Loop
bobjRs.Close
Response.Write "</select>"
Response.Write "&nbsp;&nbsp;"

If len(bxclass) > 1 Then
bstrSQL = "SELECT distinct classmd FROM s6test where class='" & bxclass & "';"
bobjRS.Open bstrSQL, bobjconn
Response.write "<select name=select3><option value=''>Month/Day</option>"    
Do While Not bobjRS.EOF 
Response.Write "<option value=" & bobjRs("classmd") & ">" & bobjRs("classmd") & "</option>"
bobjRS.MoveNext
Loop
Response.Write "</form>"
response.write "</select>"
bobjRs.Close
bobjconn.Close
end if 
%>

</body>
</html>
Reply With Quote
  #4 (permalink)  
Old April 29th, 2008, 07:05 PM
Friend of Wrox
Points: 6,478, Level: 34
Points: 6,478, Level: 34 Points: 6,478, Level: 34 Points: 6,478, Level: 34
Activity: 14%
Activity: 14% Activity: 14% Activity: 14%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,836
Thanks: 12
Thanked 16 Times in 16 Posts
Send a message via AIM to mat41
Default

Its not a bad thing re-submitting the page to achieve your objective. However why use multiple forms??? there is no need.
I would:

> get rid of multiple forms, use only one.
> when you call your onChange function submit the form!!
> you should check if your record set is empty when you create your select lists, this is just good code practice.

Anyhow here is how I would code up your first select list includig the code to ensure the previous selection remains selected:
NOTE - The below method will only work for you if each time you call the onChange function the form is submitted

 strSQL = "SELECT distinct class from s6test;"
 objRS.Open strSQL, objconn
   if not objRS.eof then %>
      <select name="xclass" onchange="reload(this.form)">
       <option value="">Class</option>
<% Do While Not objRS.EOF %>
         <option value="<%= objRs("class") %>" <% if trim(request.form("xclass")) <> "" then
                                                     if trim(request.form("xclass")) = objRs("class") then
                                                        response.write " selected "
                                                     end if
                                                  end if %>><%= objRs("class") %></option>
<% objRS.MoveNext
      Loop
      objRs.Close %>
      </select>
<% else %>
      <i>No records found</i>
<% end if %>



Wind is your friend
Matt
www.elitemarquees.com.au
Reply With Quote
Reply


Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting from multiple drop-lists Earl Hickey SQL Language 4 July 9th, 2008 04:34 PM
Linked Drop Down Lists contagiouss_blue Excel VBA 6 June 8th, 2005 10:02 AM



All times are GMT -4. The time now is 12:13 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.