944,184 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 1831
  • ASP RSS
May 14th, 2007
0

Question - ASP + Ajax

Expand Post »
Question - ASP + Ajax

Hey!

Not sure if this is the correct section to post this.

Well, I have a table in my sql server 2000 database

***************
tblAddress
----------------------------
City_Name (varchar)
Venue_Name (varchar)
*******************

The "City_Name" column contains all the name of the cities in my country and each city has multiple venues.

Now I have 2 drop-down boxes in my asp page. The first drop-down is already listed with all the cities which are in the "City_Name" column.

What I now want is, when I select a city name from the first drop-down, the second drop down should be populated with all the venue names of that city (of course without refreshing the page)

I know this can be done with ajax.

I got few codes while googling but none of them are working
Similar Threads
Reputation Points: 58
Solved Threads: 1
Posting Whiz in Training
cancer10 is offline Offline
234 posts
since Dec 2004
May 14th, 2007
0

Re: Question - ASP + Ajax

You need to query the database using ajax get or post method, and then use callback to show the second dropdown menu using innerHTML.
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
dexterz is offline Offline
86 posts
since Feb 2005
May 15th, 2007
0

Re: Question - ASP + Ajax

This is the code got, it works fine if I place a textbox instead of teh second drop-down.

main.asp file
ASP Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. <!--
  3. function myfunction()
  4. {
  5. var xmlhttp = false;
  6. //Check if we are using IE.
  7. try {
  8. //If the Javascript version is greater than 5.
  9. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  10. alert ("You are using Microsoft Internet Explorer.");
  11. } catch (e) {
  12. //If not, then use the older active x object.
  13. try {
  14. //If we are using Internet Explorer.
  15. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  16. alert ("You are using Microsoft Internet Explorer");
  17. } catch (E) {
  18. //Else we must be using a non-IE browser.
  19. xmlhttp = false;
  20. }
  21. }
  22. //If we are using a non-IE browser, create a javascript instance of the object.
  23. if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  24. xmlhttp = new XMLHttpRequest();
  25. }
  26. abc = document.getElementById('txtname').value;
  27. var obj = document.getElementById('txtshouvik');
  28. xmlhttp.open("GET", "execute.asp?str="+ abc);
  29. xmlhttp.onreadystatechange = function() {
  30. if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  31. obj.value = xmlhttp.responseText;
  32. }
  33. }
  34. xmlhttp.send(null);
  35. }
  36. //-->
  37. </script>
  38. <select name="txtCity" id="txtCity" onchange="javascript:myfunction();">
  39. <%
  40. set rsCity = conn.execute("SELECT DISTINCT Venue_City from PRS_Master_Venue")
  41. do until rsCity.eof
  42. %>
  43. <option onclick="javascript:myfunction();"><%=rsCity("Venue_City")%></option>
  44.  
  45. <%
  46. rsCity.movenext
  47. loop
  48. %>
  49. </select>
  50.  
  51. <select name="txtCity" id="txtCity" onchange="javascript:myfunction();">
  52. <option onclick="javascript:myfunction();"><%=rsCity("Venue_City")%></option>
  53. </select>
  54. <input name="btn" type="button" value="click" onClick="javascript:myfunction();"/>



execute.asp file
ASP Syntax (Toggle Plain Text)
  1. <%
  2. response.Write "Venue Name here..."
  3. %>
Reputation Points: 58
Solved Threads: 1
Posting Whiz in Training
cancer10 is offline Offline
234 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: Leave System
Next Thread in ASP Forum Timeline: paging problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC