Web Wiz - Solar Powered Eco Web Hosting

  New Posts New Posts RSS Feed - Display query results in Combobox2 based on  the s
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Display query results in Combobox2 based on the s

 Post Reply Post Reply
Author
harinarayananvp View Drop Down
Newbie
Newbie


Joined: 22 October 2011
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote harinarayananvp Quote  Post ReplyReply Direct Link To This Post Topic: Display query results in Combobox2 based on the s
    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
Back to Top
s93ncer View Drop Down
Newbie
Newbie


Joined: 08 February 2006
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote s93ncer Quote  Post ReplyReply Direct Link To This Post 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>
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.07
Copyright ©2001-2024 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Policy

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2024 Web Wiz Ltd. All rights reserved.