how to get runtime control in html?

I am creating a project .in this i want to get address through dropdownlist,if i select country from dropdownlist then another dropdownlist will apper which has the states of crresponding country.same as with state and so on till requerement?

Answers


You're looking for a "cascading dropdown". Effectively, your first dropdown, upon selection makes an ajax call which upon success populates the second dropdown and so on.

It's a very common feature (probably the most common along with ajax autocomplete) and a google or two will find you some really solid examples.

I'd strongly suggest using jQuery for such an endeavour.


  <select name="country" onchange="showstate(this.value);">

//script code
 function showstate(ctr)
  {
if (ctr==" ")
{
    document.getElementById("txtHint").innerHTML="";
    return;
}
if (window.XMLHttpRequest)
{
    xmlhttp=new XMLHttpRequest();
}
else
{
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        var x=xmlhttp.responseText;
        var arr = new Array();
        var v=new Array();
        arr=x.split(",");
        // Create an Option object        
        document.getElementById("DropDownList").innerHTML='<option value="select">Select university</option>';
        for (var i=0;i<arr.length-1;i=i+2)
        {
            v[i]=arr[i];
            v[i+1]=arr[i+1];
            document.getElementById("DropDownList").innerHTML+="<option value="+v[i]+">"+v[i+1]+"</option>";
        }
       }
      }
   xmlhttp.open("GET","getstate.php?q="+ctr,true);
   xmlhttp.send();
  }

// getstate.php

  <?php

     $q=$_GET["q"];
     $sql="SELECT DISTINCT `state` FROM `tbname` WHERE `country` = '$q'";
     $result=mysql_query($sql);
     $str='';
     while($row = mysql_fetch_array($result))
   {
    $str.=$row['country'].",";
   }
     echo $str;
?>

Need Your Help

PHP Convert Unix time to ISO and Subtract an Hour

php mysql time

I'm restructuring my MySQL database, which has several columns in Unix format.

Is it possible to control which libraries apache uses?

apache python-imaging-library libjpeg lsof

Okay, so I had an earlier problem with PIL that is still unresolved. Someone else had this problem and had success by removing the old JPEG library. I can't really do that on my machine, however, a...