468,514 Members | 1,595 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,514 developers. It's quick & easy.

One Pick List Based off of Another

1,208 Expert 1GB
Hey guys I'm having some trouble's with the following code.

Here is what I am trying to do. I have two pick list options (drop downs) and the first one pulls from a table with department names in it, these department names are also found in the PhoneBook table which the second pick list is TRYING to pull from.

Here is my issue, the first option works fine the departments display no problem. How can I change the following code to allow the Requestor field to be updated based on what the user selects in the Department field?

Basically if you pick Finance in the department field then the Requestor field should then update to show only people who work in the Finance department.

Expand|Select|Wrap|Line Numbers
  1. <tr>
  2. <td valign="center">Department</td>
  3. <td>
  4. <select name="REQUESTOR_DEPT" onChange="">
  5. <option value="">Choose One
  7. set rs = server.CreateObject("adodb.recordset")
  8. rs.Open sql, conn
  9. while not rs.eof 
  10. Response.Write("<option value='"&rs(0)&"'")
  11. if cstr(REQUESTOR_DEPT)=cstr(rs(0)) then
  12. Response.Write(" selected ")
  13. end if
  14. Response.Write(">"&rs(0))
  15. rs.movenext
  16. wend
  17. rs.close
  18. set rs = nothing
  19. %>  
  20. </select></td>
  21. <td></td>
  22. <td></td>
  23. </tr>
  24. <tr>
  25. <td valign="center">Requestor</td>
  26. <td><select name="PROF_ANAYLST_ID" onChange="">
  27. <option value="">Choose One
  28. <%sql = "SELECT LNAME+' '+FNAME FROM dbo_phonebook WHERE Department LIKE ' " & REQUESTOR_DEPT  " '"
  29. set rs = server.CreateObject("adodb.recordset")
  30. rs.Open sql, conn2
  31. while not rs.eof 
  32. Response.Write("<option value='"&rs(0)&"'")
  33. if cstr(PROF_ANAYLST_ID)=cstr(rs(0)) then
  34. Response.Write(" selected ")
  35. end if
  36. Response.Write(">"&rs(0))
  37. rs.movenext
  38. wend
  39. rs.close
  40. set rs = nothing
  41. %>  
  42. </select></td>
  43. </tr>
May 6 '10 #1
3 1759
3,405 Expert 2GB
I'm afraid asp is not set up to do this, remember ASP runs on the server and the code is dead and gone by the time the user even sees the form.

You will have to use some combination of javascript or ajax along with the ASP code to change the second select on the fly.

May 6 '10 #2
1,208 Expert 1GB
Ok so maybe some onclick javascript event that will update the second picklist value. Or something along those lines.

Thanks for the advice!
May 7 '10 #3
3,405 Expert 2GB
exactly. I've seen several solutions for this type of problem, but they all depend on Javascript or Ajax. In the minimum you could submit the form and use asp to re-build the form, but notice it still uses javascript to submit the form when the first select changes, and I think that approach is a little less-favored. I think it's a pretty common javascript problem, you should be able to google and get a hundred solutions.

May 7 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by CrystalQuery | last post: by
10 posts views Thread by Mark Winter | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.