Print Page | Close Window

Display query results in Combobox2 based on the s

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=29889
Printed Date: 28 March 2024 at 10:48pm
Software Version: Web Wiz Forums 12.07 - https://www.webwizforums.com


Topic: Display query results in Combobox2 based on the s
Posted By: harinarayananvp
Subject: Display query results in Combobox2 based on the s
Date Posted: 22 October 2011 at 1:43pm
Hi,
   I have two comboboxes,say cb1 and cb2. cb1 has 3 values,say dept1,dept2,dept3. When the value of cb1 changes,I want to retrieve values from oracle database based on the value of dept1, i.e,if I select dept1,i need to get 'select name from table1 where dept="dept1". If the selected value was dept2,then the query should be like this,'select name from table1 where dept="dept2".Then,cb2 should display all the names resulting from query.How can I do this in an asp page. Pls help. I am very new to classic asp and vbscript



Replies:
Posted By: s93ncer
Date Posted: 17 April 2012 at 8:17am
This is copied from something I wrote a while ago
It's still in use but I can see ways of improving it now I read it again

Basically, it gets a list of makes of devices from a database, and then when you select one it posts back to itself and adds a second box with a list of models.
You could use Ajax to avoid the postback of the whole page and you could use arrays but it works

...Spence


<form name='vsform' action='thisfile.asp' method='post'>
<select name='cMake' onChange='document.vsform.submit();' class="search" >
<%
sql = "SELECT DISTINCT cMake FROM devices order by cmake"
    rx.Open sql, dbConnx
    Response.Write ("<option value=''>Select Device Make</option>")
    Do While (NOT rx.EOF)
    Response.Write ("<option value='" & rx.Fields("cMake") & "' ")
      If (trim(rx.Fields("cMake")) = trim(cMake)) Then
        Response.Write ("selected>")
      Else
        Response.Write (">") 
      End If
      Response.Write (rx.Fields("cMake") & "</option>")
      rx.MoveNext
    Loop
rx.close
%>
</select>
<input type="hidden" name="oldcMake" value="<%=cMake%>" />
<%
If cMake > "" Then
%>
<select name='cModel' onChange='document.vsform.submit();' class="search">
<%
sql = "SELECT DISTINCT cModel FROM devices WHERE cmake = '" & cMake & "' order by cModel"
rx.Open sql, dbConnx
Response.Write ("<option value=''>Select Device Model</option>")
Do While (NOT rx.EOF) 
Response.Write ("<option value='" & rx.Fields("cModel") & "' ")
If (rx.Fields("cModel") = cModel) Then
Response.Write ("selected>")
Else
Response.Write (">") 
End If
Response.Write (rx.Fields("cModel") & "</option>")
rx.MoveNext
Loop
rx.close
%>
</select>
<input type="hidden" name="oldcModel" value="<%=cModel%>" />
<%
End If
%>
</form>



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.07 - https://www.webwizforums.com
Copyright ©2001-2024 Web Wiz Ltd. - https://www.webwiz.net