Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development

Sponsored Links

Discuss "drop down problem" in the ASP Development forum.

ASP Development - Learn coding practices and tips to get the best out of your Active Server Pages (ASP). The Classic ASP forum is for ASP/VBScript and ASP/JScript applications.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old July 24th, 2008, 12:57 PM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default drop down problem

Hi,

I have to populate a drop down based on the value selected from an earlier drop down.

I cant do a page submit or refresh I have to do it in javascript

the second drop down will be populated from the table

here is my code for first drop down

can someone tell me how i can open up a recordset for the second drop using javascript

Code:
<select name="Sport" id="Sport" size="1">
<option value="">Select Sport</option>
<%
strsport = "SELECT * from Sports order by SportName"
Set Rssport = Conn.Execute(strsport)
if not Rssport.eof then
	Do while not Rssport.Eof
%>
<option value="<%=Rssport("SportName")%>"><%=Rssport("SportName")%></option>
<%
Rssport.movenext
loop
End if
Rssport.close
Set Rssport=Nothing
%>
</select>
Reply With Quote
Sponsored Links
  #2  
Old July 24th, 2008, 01:24 PM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

You can't. You'd have to use AJAX since the ASP script runs on the server, not the client. See Mega site of Bible studies and information for an AJAX intro.
__________________
Wolffy
------------------------
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.
Reply With Quote
  #3  
Old July 24th, 2008, 01:55 PM
BLaaaaaaaaaarche's Avatar
Administrator


 
Join Date: Mar 2008
Posts: 55
Thanks: 10
Thanked 7 Times in 5 Posts
Rep Power: 1
BLaaaaaaaaaarche is on a distinguished road

Awards Showcase
HTML & CSS Classic ASP 
Total Awards: 2

Default

Okay, time to rant. I HATE spaghetti code. It is ugly, hard to read, and just plain sucks. So, what I like to do, is to create SUBS. This way, you can globalize them and use them on one, or many pages. Also, why are you passing the SportName as the value of the dropdown. You should ALWAYS use the unique ID for that SportName. Anyways, I didn't tinker with that, but here you go:

Code:
Sub SelectSport(SportName)
	' -- Create SQL --
	strSQL = "SELECT SportName FROM Sports ORDER BY SportName"
	Set rsSport = conn.Execute(strSQL)

	' -- Create Dropdown --
	response.write "<select name=""sport"" id=""sport"" size=""1">" & vbCrLf
	response.write "<option value="""">Select Sport</option>" & vbCrLf

	' -- Loop Through RS --
	If Not rsSport.EOF Then
		Do While Not rsSport.EOF
			response.write "<option value=""" & rsSport("SportName") & """"
			If CStr(SportName) = CStr(rsSport("SportName")) Then
				response.write " selected"
			End If
			response.write ">" & rsSport("SportName") & "</option>" & vbCrLf
		rsSport.MoveNext
		Loop
	End If

	' -- Close Dropdown --
	response.write "</select>" & vbCrLf

	' -- Close Connection --
	rsSport.Close
End Sub
Then, to call it, you simply use this bit of code where you need it displayed:

Code:
SportName = Request.Form("sport")
Call SelectSport(SportName)
I am assuming that you are setting the value from the drop down in the variable called SportName.
__________________
"You'll never be as perfect as BLaaaaaaaaarche."
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > ASP Development

Bookmarks

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
drop down problem todd2006 JavaScript Programming 32 July 1st, 2008 04:46 PM
display problem with drop downs todd2006 JavaScript Programming 3 May 5th, 2008 05:31 PM
drop down problem todd2006 .Net Development 2 April 23rd, 2008 11:37 AM


All times are GMT -4. The time now is 05:20 PM.



Content Relevant URLs by vBSEO 3.2.0