User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 422,558 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,677 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2444 | Replies: 0
Reply
Join Date: Dec 2006
Posts: 1
Reputation: kaniths is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kaniths kaniths is offline Offline
Newbie Poster

Help HELP reg:: Dynamic Dependant Dropdown

  #1  
Dec 20th, 2006
hey frends..
i have to create a asp page with 2 select pulldowns(state,city),options to b displayed in the CITY depends on STATE choice.

the option list is to retrived from a db dynamically.

i have a table with fields--state,stateID,city,cityID.

here is the code snippet i have..

  1.  
  2. <html>
  3. <head>
  4. <title>testpage</title>
  5. <script language=javascript >
  6. var States = new Array();
  7. var Cities = new Array();
  8.  
  9. function addState(state) {
  10.  
  11. v = States.length;
  12. States.length ++;
  13. States[v] = state;
  14. v = Cities.length;
  15. Cities.length ++;
  16. Cities[state] = new Array();
  17. }
  18.  
  19. function addCity(state,city) {
  20. v = Cities[state].length;
  21.  
  22. Cities[state].length ++;
  23.  
  24. Cities[state][v] = city;
  25. }
  26.  
  27. function loadStateList() {
  28.  
  29. var ctrlState = document.frmAddress.State;
  30. ctrlState.options.length = 0;
  31. for (i=0;i<States.length;i++) {
  32. ctrlState.options[i] = new Option(States[i],States[i]);
  33. }
  34. }
  35.  
  36. function loadCityList() {
  37.  
  38. var ctrlState = document.frmAddress.State;
  39. var selState = ctrlState.options[ctrlState.selectedIndex].value;
  40.  
  41. var ctrlCity = document.frmAddress.City;
  42. ctrlCity.options.length = 0;
  43.  
  44. for (i=0;i<Cities[selState].length;i++) {
  45. ctrlCity.options[i] = new Option(Cities[selState][i]);
  46. }
  47. }
  48. </script>
  49.  
  50. </head>
  51. <body onload="loadStateList();loadCityList();">
  52.  
  53. <%
  54. ' Open Database and setup a recordset with States Listed.
  55. set conn = server.createobject("ADODB.Connection")
  56. Conn.open("driver={SQL Server};server=xxxxxxx;uid=xxxxxxx;pwd=xxxxxxx;database=xxxxxxx;network=dbmssocn")
  57. strSQL = "Select State, city from tbAddress Order by State,city"
  58. set rs = conn.execute(strSQL)
  59.  
  60.  
  61. if rs.eof then
  62. response.write("No Addresses Found")
  63. rs.close
  64. set rs=nothing
  65. response.end
  66. end if
  67.  
  68. strState = ""
  69. strCity = ""
  70. do until rs.eof
  71. if not rs("State") = strState then
  72. response.write("<script>addState('" & rs("State") & "')</script>")
  73. response.write("<script>addCity('" & rs("State") & "','" & rs("City") & "')</script>")
  74. strState = rs("State")
  75. strCity = rs("City")
  76. else
  77. if not rs("City") = strCity then
  78. response.write("<script>addCity('" & rs("State") & "','" & rs("City") & "')</script>")
  79. strCity = rs("City")
  80. end if
  81. end if
  82. rs.MoveNext
  83. loop
  84. rs.close
  85. set rs=nothing
  86. %>
  87.  
  88.  
  89. <form name="frmAddress" method="POST" action="">
  90. <table>
  91. <tr>
  92. <td>STATE ID:</td>
  93. <td><input type=text hidden="true" name="text1" /></td>
  94. </tr>
  95. <tr>
  96. <td>CITY ID</td>
  97. <td><input type=text hidden="true" name="text2" /></td>
  98. </tr>
  99. <tr>
  100. <td>State</td>
  101. <td>
  102. <select size="1" name="State" onChange="loadCityList();">
  103. </select>
  104. </td>
  105. </tr>
  106. <tr>
  107. <td>City</td>
  108. <td>
  109. <select size="1" name="City">
  110. </select>
  111. </td>
  112. </tr>
  113. </table>
  114. <p>
  115. <input type="submit" value="Submit" name="save" />
  116. <input type="reset" value="Reset" name="clear" />
  117. </p>
  118. </form>
  119. </body>
  120. </html>

NOW..how can i modify the code,so that wen the option is selected in the STATE & CITY lists,simulteneously the stateID,cityID are filled in 2 hidden textboxes,Text1 & Text2..

kindly help..
thanks..

regards,
kanith
Last edited by kaniths : Dec 20th, 2006 at 10:54 am.
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 1:13 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC