DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Fill Combo Using Ajax + Php

06.05.2009
| 4973 views |
  • submit to reddit
        onchange="ajaxFunction(this.value,'{$smarty.server.HTTP_USER_AGENT}');"

 <select name="MCATXintCId" id="MCATXintCId" onchange="ajaxFunction(this.value,'{$smarty.server.HTTP_USER_AGENT}');">
                                       {section name=catsec loop=$catdata}
                                       <option value="{$catdata[catsec].MCATXintCId}" {*if $smarty.post.MCATXintCId neq ""} {if $smarty.post.MCATXintCId eq $catdata[catsec].MCATXintCId} selected="selected" {/if} {else*} {if $catdata[catsec].MCATXintCId eq $MCATXintCId} selected="selected" {/if}{*/if*}>{$catdata[catsec].MCATXTit}</option>
                                       {/section}
                                    </select>
                                    
<script language="javascript" type="text/javascript">
function ajaxFunction(cid,explor)
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      // alert(explor);
     var browsr = getBrowserName();
      
       
          if(browsr == 'Microsoft Internet Explorer')
          {
              document.getElementById('subcatid').innerHTML = '<img src="../images/progress_bar_animated.gif" width="10px" heigh="10px" >';
              
             document.getElementById('subcatid').innerHTML = xmlHttp.responseText; 
          }
          else
          {
             //document.getElementById('subcatid').innerHTML = '<img src="../images/progress_bar_animated.gif" width="10px" heigh="10px" >';
             document.getElementById('MSCATXintSCId').innerHTML = xmlHttp.responseText; 
          }
         
        //document.getElementById('MSCATXintSCId').innerHTML = xmlHttp.responseText;
        
      }
    }
  xmlHttp.open("GET","getsubcate.php?cid="+cid,true);
  xmlHttp.send(null);
  }
  function getBrowserName()   {   

   return document.forms[0].elements[0].value =navigator.appName;     

}
		                                                   
</script>