ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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:
  #1  
Old November 22nd, 2010, 03:14 PM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
Dependant drop down box

Hi..

[asp/vbscript/javascript]

I am using dependent dropdown box in my program..
If i select the value in the first drop down..based on the value fields in the second drop down should change using databse.



first drop down: country
second drop down:state
Based on country the values in the second drop down should display the states.


can anyone know how to use dependant drop down.. plese give me an example..


Thanks..

Reply With Quote
  #2  
Old November 22nd, 2010, 07:43 PM
Vomster's Avatar
Vomster Vomster is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2005
Posts: 724 Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 2 h 26 m 31 sec
Reputation Power: 290
You couldn't get jQuery to work for you?

Reply With Quote
  #3  
Old November 22nd, 2010, 09:02 PM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
No I couldn't get the result..

I am trying the various ways...

If anyone know plz give me an example ...

Reply With Quote
  #4  
Old November 23rd, 2010, 07:28 AM
Vomster's Avatar
Vomster Vomster is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2005
Posts: 724 Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 2 h 26 m 31 sec
Reputation Power: 290
You're going to need javascript to do it.

I'll see if I can mock one up for you tonight using jQuery if you like.

Reply With Quote
  #5  
Old November 23rd, 2010, 07:32 AM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
This is the code i am using..
But there is wrong result it is showing..When you select an item in first dropdown the values are changing in the second drop down..this one working fine for first time...

If I change the values in the first drop down at second time (without refreshing the browser), the second drop down values are changing and the same time previous values are appending..

The out put is not I expected..

Code:
<%
OpenSQLConn	

if request("submit") <> "" then
			
		
		listbox1=Request.form("listbox1")
  		listbox2=Request.form("listbox2")
		sql1="select * from master where menu_id='"& listbox1 &"'"
		set rs=Conn.execute(sql1)
		'response.write("afterif")
		
%>	 
<table border="1">	
<tr>
     <th>Menu Type</th>
     <th>Size</th>
     <th>Itemid</th>
      <th>Quantity</th>
</tr>
	<%
		do until rs.EOF
   		response.write("<tr>")
   		response.write("<td>" & rs("menu_id") & "</td>")
   		response.write("<td>" & rs("sizeid") & "</td>")
   		response.write("<td>" & rs("itemid") & "</td>")
   		response.write("<td>" & rs("quantity") & "</td>")
   		  
   		response.write("</tr>")
   		rs.MoveNext
		loop
		rs.close
		Conn.Close

	%>
</table>

<%		
	end if
 %>	




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Dependent Dropdownlists</title>


<%
Dim myRS 'Object
Dim mySQL 'String
Dim StartAuthor 'String
Dim Cnt 'Integer
Dim ListBox1 'String


%>

<script language="javascript">
function listboxchange(p_index)
{
<%
mySQL = "SELECT * FROM menu Order By menuid "

'Get Recordset using our SQL
Set myRS = Conn.Execute(mySQL) 
%>
switch (p_index)
{
<%
'Loop Through all authors and books
Do Until myRS.eof 
StartAuthor = myRS("menuid")
Cnt = 0

%>
case "<%=StartAuthor%>" :
<% 

do until myrs.eof or StartAuthor <> myRS("menuid")
%>
document.myform.listbox2.options[<%=cnt%>]=new Option("<%=myRs("sizeid")%>","<%=myRs("size")%>");
<%
Cnt = Cnt + 1
myrs.movenext
if myrs.eof then exit do
Loop
%>
break;
<%
Loop

%>
}
return true;
}
</script>


<%
mySQL = "SELECT DISTINCT menuid FROM menu Order By menuid asc"


Set myRS = Conn.Execute(mySQL) 

'Make Drop down box Author list 
do until myrs.eof
ListBox1 = ListBox1 & "<option value=""" & myRs("menuid") & """>" & myRs("menuid") & "</option>"
myRs.movenext
loop

myRS.close
Set myRS = nothing 
Conn.close

%>
</head>
<body>
<form name="myform" action="" method="get">
<select name="listbox1" id="listbox1" onChange="javascript: listboxchange(this.options[this.selectedIndex].value);">
<option value="">Please Select</option>
<%=ListBox1%>
</select>

<select name="listbox2">
<option value="">Please Select</option>
</select>
<input type="submit" name="submit" value="show values" />
</form>


</body>
</html>




[MYSQL]Sql table:
menu table[menuid(pk),menu]
size table[sizeid(pk),size]
master table[menu_id(fk),sizeid(fk),menu_type][/MYSQL]
my desired out put is
menuid,sizeid,size


Can any one find out the error..and the same time i didn't understand the code much..

Reply With Quote
  #6  
Old November 23rd, 2010, 08:14 AM
Vomster's Avatar
Vomster Vomster is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2005
Posts: 724 Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 2 h 26 m 31 sec
Reputation Power: 290
Change the following line from this
Code:
sql1="select * from master where menu_id='"& listbox1 &"'"

to this
Code:
sql1="select menu_id,sizeid,size from master m join size s on s.sizeid = m.sizeid where menu_id='"& listbox1 &"'"



As a side note, I see that you are getting the quantity but I see no quantity in any of your tables.

I don't think it'll work the way you intend for it too. Try using the script I gave you and comment out the quantity for now and see if that works.

Reply With Quote
  #7  
Old November 23rd, 2010, 08:42 AM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
It is displying which is not necessary..

first dropdown i selected 101 and
second dropdown i selected size as 'S'

It should display the output
101 s

but it is displaying
101 S
101 M.. both.

here the second dropdown is not working..

Reply With Quote
  #8  
Old November 23rd, 2010, 09:01 AM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
Do I need to pass two values(listbox1 and listbox2) in sql query..
like as you mentioned in that..

Reply With Quote
  #9  
Old November 23rd, 2010, 09:47 AM
Vomster's Avatar
Vomster Vomster is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2005
Posts: 724 Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level)Vomster User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 2 h 26 m 31 sec
Reputation Power: 290
Yes, you will need to pass both.

Code:
sql1="select menu_id,sizeid,size from master m join size s on s.sizeid = m.sizeid where menu_id='"& listbox1 &"'" and s.sizeid = '" & listbox2 & "'"

Reply With Quote
  #10  
Old November 23rd, 2010, 02:59 PM
lucky20 lucky20 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 39 lucky20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
Got it..Thank you.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Dependant drop down box

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap