The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> ASP Programming
|
Dependant drop down box
Discuss Dependant drop down box in the ASP Programming forum on Dev Shed. Dependant drop down box ASP Programming forum discussing Active Server Pages coding techniques and problem solving methods. Use VBScript or Jscript to make dynamic web applications.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 22nd, 2010, 03:14 PM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
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..
|

November 22nd, 2010, 07:43 PM
|
 |
Contributing User
|
|
|
|
|
You couldn't get jQuery to work for you?
|

November 22nd, 2010, 09:02 PM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
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 ...
|

November 23rd, 2010, 07:28 AM
|
 |
Contributing User
|
|
|
|
|
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.
|

November 23rd, 2010, 07:32 AM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
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..
|

November 23rd, 2010, 08:14 AM
|
 |
Contributing User
|
|
|
|
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.
|

November 23rd, 2010, 08:42 AM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
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..
|

November 23rd, 2010, 09:01 AM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
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..
|

November 23rd, 2010, 09:47 AM
|
 |
Contributing User
|
|
|
|
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 & "'"
|

November 23rd, 2010, 02:59 PM
|
|
Contributing User
|
|
Join Date: Nov 2010
Posts: 39
Time spent in forums: 4 h 32 m 58 sec
Reputation Power: 3
|
|
|
Got it..Thank you.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|