SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Populate dependent drop down list from database using Ajax and classic asp

    i just populated triple drop down list from database using Ajax and asp as Country, State, City..now i need to create one more drop down list after City...

    Here is my script

    Code JavaScript:
    <script language="javascript" type="text/javascript">
    function getXMLHTTP() { 
    		var xmlhttp=false;	
    		try{
    			xmlhttp=new XMLHttpRequest();
    		}
    		catch(e)	{		
    			try{			
    				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
    			}
    			catch(e){
    				try{
    				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    				}
    				catch(e1){
    					xmlhttp=false;
    				}
    			}
    		}
     
    		return xmlhttp;
        }
     
    	function getState(countryId) {		
     
    		var strURL="findState.asp?country="+countryId;
    		var req = getXMLHTTP();
     
    		if (req) {
     
    			req.onreadystatechange = function() {
    				if (req.readyState == 4) {
    					// only if "OK"
    					if (req.status == 200) {						
    						document.getElementById('statediv').innerHTML=req.responseText;						
    					} else {
    						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    					}
    				}				
    			}			
    			req.open("GET", strURL, true);
    			req.send(null);
    		}		
    	}
    	function getCity(countryId,stateId) {		
    		var strURL="findCity.asp?country="+countryId+"&state="+stateId;
    		var req = getXMLHTTP();
     
    		if (req) {
     
    			req.onreadystatechange = function() {
    				if (req.readyState == 4) {
    					// only if "OK"
    					if (req.status == 200) {						
    						document.getElementById('citydiv').innerHTML=req.responseText;						
    					} else {
    						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    					}
    				}				
    			}			
    			req.open("GET", strURL, true);
    			req.send(null);
    		}
     
    	}
    </script>

    and here is my asp code...

    Code ASP:
    <form method="post" action="" name="form1">
    <table width="60%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="150">Country</td>
        <td  width="150"><select name="country" onChange="getState(this.value)">
    	<option value="">Select Country</option>
        <%while not rsCountry.eof%>
    	<option value="<%=rsCountry("CountryID")%>"><%=rsCountry("Country")%></option>
    	<%rsCountry.movenext
    	wend
    	rsCountry.close
    	set rsCountry = nothing
    	objConn.close%>
            </select></td>
      </tr>
      <tr style="">
        <td>State</td>
        <td ><div id="statediv"><select name="state" >
    	<option>Select Country First</option>
            </select></div></td>
      </tr>
      <tr style="">
        <td>City</td>
        <td ><div id="citydiv"><select name="city">
    	<option>Select State First</option>
            </select></div></td>
      </tr>
    </table>
    </form>

    Can anybody help me to create 4th drop down list...
    Thanks in advance...
    Last edited by Mittineague; Dec 9, 2013 at 23:12. Reason: reformatting bbcode tags


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •