Question - ASP + Ajax

Reply

Join Date: Dec 2004
Posts: 234
Reputation: cancer10 is an unknown quantity at this point 
Solved Threads: 0
cancer10's Avatar
cancer10 cancer10 is offline Offline
Posting Whiz in Training

Question - ASP + Ajax

 
0
  #1
May 14th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 86
Reputation: dexterz is an unknown quantity at this point 
Solved Threads: 3
dexterz dexterz is offline Offline
Junior Poster in Training

Re: Question - ASP + Ajax

 
0
  #2
May 14th, 2007
You need to query the database using ajax get or post method, and then use callback to show the second dropdown menu using innerHTML.
Dexter Zaf
Ex-designz.net
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 234
Reputation: cancer10 is an unknown quantity at this point 
Solved Threads: 0
cancer10's Avatar
cancer10 cancer10 is offline Offline
Posting Whiz in Training

Re: Question - ASP + Ajax

 
0
  #3
May 15th, 2007
This is the code got, it works fine if I place a textbox instead of teh second drop-down.

main.asp file
  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
  1. <%
  2. response.Write "Venue Name here..."
  3. %>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC