469,330 Members | 1,334 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

ajax code for combo box(list box)

18
hi dere,

i'm new to ajax.. i did a small example using it successfully.. but the problem i'm facing is, how to display the data in a combo box.. if i know the no.of values that is coming from db i can do it, however i don know the no.of records in db..

to be more simple, if i select a country, corr.states of that country should come..
below is the code i used to dispaly if i kno the no.of records in the db

Expand|Select|Wrap|Line Numbers
  1. function ajaxFunction()
  2. {
  3. var xmlHttp;
  4. try
  5.   {  // Firefox, Opera 8.0+, Safari 
  6.   xmlHttp=new XMLHttpRequest();
  7.   }
  8. catch (e)
  9.   {  // Internet Explorer  
  10.   try
  11.     {    
  12.     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  
  13.     }
  14.   catch (e)
  15.     {   
  16.     try
  17.       {     
  18.       xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");   
  19.       }
  20.     catch (e)
  21.       {    
  22.       alert("Your browser does not support AJAX!");   
  23.       return false;    
  24.       } 
  25.       } 
  26.       }
  27.   xmlHttp.onreadystatechange=function()
  28.     {
  29.     if(xmlHttp.readyState==4)
  30.       {
  31.       var array;
  32.       array=xmlHttp.responseText.split("|")
  33.       document.form2.contact.value=array[0];
  34.       document.form2.address.value=array[1];
  35.       document.form2.city.value=array[2];
  36.       document.form2.country.value=array[3];
  37.       }
  38.     }
  39.     var user= document.form2.user.value
  40.     var url = "aswajax?user=" + user;
  41.   xmlHttp.open("GET",url,true);
  42.   xmlHttp.send();  }

any help..
thanks in advance..
regards,
aswathn.s
(knowledge is power
Mar 25 '08 #1
1 1574
acoder
16,027 Expert Mod 8TB
Either use XML or JSON, or after splitting, use a for loop to loop over the data. That way you don't need to know the number of records.
Mar 25 '08 #2

Post your reply

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

Similar topics

4 posts views Thread by access baby | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.